[Tutor] Closeing a file written to by cPickle dump

orbitz orbitz at ezabel.com
Sat Nov 27 22:07:13 CET 2004


In your example you do not have an object to close since you open it in 
the dump call.  Also, you open it for writing only in your example so 
you will need to reopen it if you plan to read from it. If you want to 
read and write to it you'll need to open it for reading and writing and 
when you are done rewind the cursor so you are at the front.


Dave S wrote:

> 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
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



More information about the Tutor mailing list