Simple File I/O Question

Erno Kuusela erno at iki.fi
Fri Jul 14 14:46:39 EDT 2000


>>>>> "Curtis" == Curtis Jensen <cjensen at bioeng.ucsd.edu> writes:

    Curtis> So, How do I write an int variable to a file?  Thanks.

you can only write strings into files. you could convert
your integer object into a string, but then you could not
tell the difference between and a string when you read it back.
it might be ok for you, or it might not.

if you want more perfect saving of objects into files, you can
use the cPickle module to serialize them into string form,
and back again. it can handle almost any kind of object, including
most of python's built-in types and instances of python classes.
see the cPickle documentation for more information on this.

   -- erno




More information about the Python-list mailing list