aleax at aleax.it
Mon Mar 3 16:32:43 CET 2003
Eliran Gonen wrote:
> I want to ask you what do you think is the best way to keep
> a list of books with other data (such as year and author) in a
> file ?
That depends on your purposes and on the size the database
is likely to grow to.
> And what way should be used to parse it ?
That depends on what format you're keeping it in.
> Is something like:
> Is alright ?
I don't like it at all -- neither fish nor fowl, and you're
likely to have to write your own parser for it -- not trivial,
though not a really big deal -- naah.
XML is probably OK:
<book name="Example" author="Somedood" year="1969"/>
<book name="Wuffy" author="Puffy" year="2010"/>
and you can parse it easily with SAX, for example.
Or if the fields you want to record for each book are fixed
and you "know" they'll never contain (e.g.) newlines and
vertical bars, you could use a one-line-per-record, fields-
and "parse" this with [ rec[:-1].split('|') for rec in afile ].
More information about the Python-list