Python and Ruby

Paul Rubin no.email at nospam.invalid
Wed Feb 3 18:09:37 EST 2010


Lou Pecora <pecora at anvil.nrl.navy.mil> writes:
> after much noodling around and reading it hit me that I could just put
> all that output of different types of variables into a list, hit it
> with a repr() function to get a string version, and write the string
> to a file -- no formatting necessary-- three lines of code. Later
> reading in the string version (no formatting necessary), and hitting
> it with an eval() function returned all the values I originally had in
> those variables.  How simple, but beautiful.

FYI: I do that too sometimes, but in general using repr/eval that way
is poor style and not very reliable.  It's better to use the pickle
module, which is intended for that sort of thing, or the json module
if your datatypes are suitable and you want to follow a semi-standard.



More information about the Python-list mailing list