Python and Ruby

Lou Pecora pecora at anvil.nrl.navy.mil
Thu Feb 4 09:59:29 EST 2010


In article <7x8wb9j4r2.fsf at ruckus.brouhaha.com>,
 Paul Rubin <no.email at nospam.invalid> wrote:

> 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.

Yeah, I should look into pickle.  Haven't messed with that.  Most of 
what I do is numerical calculations for my consumption/research so quick 
and easy comes first.  Thanks for the hint.

-- 
-- Lou Pecora



More information about the Python-list mailing list