Loading a Python collection from an text-file

Magnus Lycka lycka at carmen.se
Fri Jan 27 07:45:58 EST 2006


Ilias Lazaridis wrote:
> jschull at gmail.com wrote:
> 
>> another approach (probably frowned upon, but it has worked for me) is
>> to use python syntax (a dictionary, say, or a list) and just import (or
>> reload) the file
>>
> 
> this sounds good.
> 
> can I import a whole collection of instances this way?

Sure, it's just a Python module with variables in it.

I wouldn't try to teach my users Python syntax though.

If you really need this kind of data structure freedom,
I'd lean towards YAML or possibly XML. (XML isn't too
bad if you provide good tools. It's not a good idea
with just a text editor.)

If a spreadsheet like layout is enough, I (still)
recommend csv.



More information about the Python-list mailing list