python and parsing an xml file

Stefan Behnel stefan_ml at behnel.de
Mon Feb 21 20:03:49 CET 2011


Terry Reedy, 21.02.2011 19:22:
> 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?
>
> ...
>> 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. Or if I needed cross language
> portability, a JSON file, which is close to the same thing.

Hmm, right, good call. There's also the configparser module in the stdlib 
which may provide a suitable format here.

Stefan




More information about the Python-list mailing list