python and parsing an xml file

Matt Funk mafunk at nmsu.edu
Mon Feb 21 23:08:07 CET 2011


Hi Terry,

On 2/21/2011 11:22 AM, Terry Reedy wrote:
> On 2/21/2011 12:30 PM, Matt Funk wrote:
>> Hi,
>> I was wondering if someone had some advice:
>> I want to create a set of xml input files to my code that look as
>> follows:
>
> Why?
mmmh. not sure how to answer this question exactly. I guess it's a
design decision. I am not saying that it is best one, but it seemed
suitable to me. I am certainly open to suggestions. But here are some
requirements:
1) My boss needs to be able to read the input and make sense out of it.
XML seems fairly self explanatory, at least when you choose suitable
names for the properties/tags etc ...
2) I want reproducability of a given run without changes to the code.
I.e. all the inputs need to be stored external to the code such that the
state of the run is captured from the input files entirely.



>
>
> ...
>> So there are comments, whitespace etc ... in it.
>> I would like to be able to put everything into some sort of structure
>> such that i can access it as:
>> structure['Algorithm']['Type'] == Alg1
>
> Unless I have a very good reason otherwise, I would just put
> everything in nested dicts  in a .py file to begin with. 
That is certainly a possibility and it should work. However, eventually
the input files might be written by a webinterface (likely php). Even
though what you are suggesting is still possible it just feels a little
awkward (i.e. to use php to write a python file).


> Or if I needed cross language portability, a JSON file, which is close
> to the same thing.
>
again, i am certainly not infallible and open to suggestions of there is
a better solution.


thanks
matt




More information about the Python-list mailing list