loading dictionary from a file

Fuzzyman fuzzyman at gmail.com
Thu Feb 7 03:55:10 EST 2008



Amit Gupta wrote:
> Need a python trick, if it exists:
>
> I have a file that stores key, value in following format
> --
> "v1" : "k1",
> "v2" : "k2"
> --
>
> Is there a way to directly load this file as dictionary in python. I
> could do (foreach line in file, split by ":" and then do dictionary
> insert). Wondering, if some python built-in function can just read a
> valid dictionary-file and load it?
>

If you change the format slightly you could use ConfgiObj <
http://www.voidspace.org.uk/python/configobj.html >.

key = value
"key2" = "value2"

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



> Thanks



More information about the Python-list mailing list