[Tutor] Closeing a file written to by cPickle dump

Dave S pythontut at pusspaws.net
Sat Nov 27 21:57:57 CET 2004


So far when I have needed to write to a file I have:

......
import time,smtplib,os,sys
.....
....
logfile=open(logdir+'log','w')
logfile.write(blog)
logfile.close()
   

Now I need to use pickle to save dictionaries, I have started:

.....
from cPickle import dump
......
dump(dict,open(data_dir+'/'+save_name,'w'))

It appears to work OK & I can read from the pickle but in this dump 
format do I need to close the open file with an equiverlant of 
xxx.close(). Am I in danger of data not being flushed to the hard drive ?

If I do need to close it, how do I do that because there is no class 
instance ?

Cheers
Dave




More information about the Tutor mailing list