Possibility and Probability

A Python programmer with a personality thinking about space exploration

6 August 2006

Plowing on

by Nick

In yesterday’s post I was “contemplating” the experience of coding up something to work with XML. Specifically, I was kinda stuck because the results I was getting weren’t really helping me move forward on creating something to translate XML into Python objects. As is usually the case I made the whole situation harder than it needed to be. I was trying to write a solution that involved a recursive function and it wasn’t working the way I expected it too. The neat thing about recursive functions is that they can be re-written as a form of a loop, so I used that approach to help debug the errors I was getting. Having a good debugger was essential also. Without the pydev plugin for eclipse, it would have taken forever to figure out what DOM objects I was looking at. Being able to set a breakpoint and look at a live object was priceless. It turns out that the DOM object had more things in it in different places than what I was expecting. Having to guess and do a million print’s would have taken what little bit of sanity I have left. :) Your tip for the day is that Python’s setattr() and getattr() functions rock. They allow you to inspect and modify member attributes of a class. After reading though Dave Mertz’s articles (here and here), it became very clear how I could use these functions in my own code to build objects from XML. Now I can move forward and start using that loaded data to actually do something interesting…

tags: