Using ConfigParse

Peter Otten __peter__ at web.de
Tue Jun 8 06:35:43 EDT 2004


Zunbeltz Izaola wrote:

>     def save(self):
>         print "Enter save"
>         self.write(open('defaultdifrac.cfg','w'))
>         self.read(open('defaultdifrac.cfg'))
>         print "OUt save"
 
I would explicitly close the file before trying to read it. 

>>> def save(fn="tmp.txt", s="so what", close=True):
...     f = file(fn, "w")
...     f.write(s)
...     if close: f.close()
...     return file(fn).read()
...
>>> save()
'so what'
>>> save(s="another")
'another'
>>> save(s="yet another", close=False)
''

Peter




More information about the Python-list mailing list