[Tutor] xml question

Albert-Jan Roskam fomcl at yahoo.com
Tue Jul 27 20:25:49 CEST 2010

Thank you all for your replies; they were most useful! I've never made a connection between xml and mass-suicide  ---interesting. ;-) Yaml seems a good choice (I didn't llook at config parser yet). In my office, we use Python and R (among other tools) and therfore it seems best not to use some pure python config file format. I agree that the readability/editability (by humans) of a yaml file is a huge advantage. Today I experimented with the yaml library of R and it felt very intuitive. I expect this will be the same for Python (not in the last place because Python is such a *beautiful*, clear language ;-)




All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?


--- On Tue, 7/27/10, Mac Ryan <quasipedia at gmail.com> wrote:

From: Mac Ryan <quasipedia at gmail.com>
Subject: Re: [Tutor] xml question
To: tutor at python.org
Date: Tuesday, July 27, 2010, 11:46 AM

On Mon, 2010-07-26 at 12:09 -0700, Albert-Jan Roskam wrote:
> I am making a data processing program that will use a configuration
> file. The file should contain information about: (1) source files
> used, (2) (intermediate) output files, (3) used parameters/estimation
> methods (4) manual data edits + datetime stamp + user name . I'd like
> to store this config file in xml. However, I've never created
> something like this before. Is this a suitable format, and, if so,
> what would the elementtree look like? Should I just use 'config'  or
> something similar as root, and the information elements 1 through 3 as
> child elements? And should the manual edits be stored as an element
> 'edit' with various attributes (the edit itself, the time stamp,
> etc.)?

I am with Steven on the fact that XML might not necessarily be the best
choice, unless you plan to use the configuration file with other
third-party programs, in which case the fact that XML has built-in
parsing libs for nearly all languages makes life of fellow developer

For the next project of mines, I am planning to use YAML (YAML Ain't a
Markup Language). I stumbled upon this format while toying around with
the google app engine, that uses it for storing your application
configuration data. IMO, YAML has the following prominent advantages:
   1) It is easy to read and edit by humans [think "markdown"]
   2) It has solid parsing libraries for Python
   3) It is far less verbose than XML
   4) It is consistent with Python "relevant whitespaces" [indentation
is used to define data structure hierarchy]

I have not yet got to the stage of writing code that use YAML (will take
two more weeks at best for me to get to that point), but should you go
down this road, I would love to hear back from you. [As I would love to
hear from anybody else who might have experience with YAML+Python]

Some links:
- http://en.wikipedia.org/wiki/YAML [good overview of the format]
- http://www.yaml.org/ [official site... when consistency with the
format makes a website hard to browse!]
- http://pyyaml.org/wiki/PyYAMLDocumentation [documentation of the
library for Python - pure Python code // can use a C library]

An example of YAML file to give you the taste of it:
> receipt:     Oz-Ware Purchase Invoice
> date:        2007-08-06
> customer:
>     given:   Dorothy
>     family:  Gale
> items:
>     - part_no:   A4786
>       descrip:   Water Bucket (Filled)
>       price:     1.47
>       quantity:  4
>     - part_no:   E1628
>       descrip:   High Heeled "Ruby" Slippers
>       price:     100.27
>       quantity:  1
> bill-to:  &id001
>     street: |
>             123 Tornado Alley
>             Suite 16
>     city:   East Westville
>     state:  KS
> ship-to:  *id001
> specialDelivery:  >
>     Follow the Yellow Brick
>     Road to the Emerald City.
>     Pay no attention to the
>     man behind the curtain.


Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100727/27e7be8f/attachment-0001.html>

More information about the Tutor mailing list