CONTEST - What is the (best) solution?

Fuzzyman fuzzyman at gmail.com
Thu Feb 3 08:47:50 EST 2005


By the way - all suggestions so far rely on chopping the last
dictionary out as a string (naturally) and then using 'eval' to
evaluate it.

This has the inherent security problem that embedded python code will
also be run. This is not just a security risk (which may *not* be an
issue) but might cause extremely unpredictable results - which will be
I guess. Text might be evaluated as an expression.

There already exists a small python module called ConstructParser by
John Berninger that will read dictionaries from strings and reconstruct
them without using eval. You'll still need to isolate the actual
dictionary you want.

Google for it, if you can't find it - email me and I'll send you a
copy. It's nice and small.....

If you want a script that will load and save dictionaries you could use
ConfigObj. It uses the text format of 'ini' files ( keyword=value), but
is very easy to use. http://www.voidspace.org.uk/python/configobj.html

Regards,


Fuzzyman
http://www.voidspace.org.uk/python/index.shtml




More information about the Python-list mailing list