[Tutor] File Input of "Objects"
chuck at freshsources.com
Wed Jun 1 23:42:27 CEST 2005
I notice that with 'print >> f' one can print the string
representation of objects to a file. Is there a corresponding input
facility that parses through a file creating objects? I can't find
one. In the meantime, I did this:
>>> f = open('out.dat','w')
>>> print >> f, 1, 2
>>> s = open('out.dat').read()
>>> x,y = tuple(map(eval,s.split()[:2]))
This is just what came to mind without thought. Is there a Pythonic
way to read formatted objects? Thanks.
-- Chuck Allison
More information about the Tutor