files and reading from them

Delaney, Timothy tdelaney at avaya.com
Mon Mar 25 17:51:36 EST 2002


> From: Sheila King [mailto:usenet at thinkspot.net]
> 
> Technically, you can accomplish this by
> 
> x = eval(file.readline())
> 
> if you know for a fact that your line of text from the file will be a
> correctly formatted, string representation of a dictionary, 
> and that you can depend on that 100%, no ifs, ands or buts.

Also, only if for each item in the dictionary (key and value)
eval(repr(item)) returns an object equivalent to item. For builtins, this is
the case - for user-defined classes it often (usually even) isn't.

Tim Delaney




More information about the Python-list mailing list