[Tutor] Need help appending data to a logfile

Alan Gauld alan.gauld at btinternet.com
Sun Jun 30 16:52:39 CEST 2013


On 30/06/13 15:04, Matt D wrote:
>
> that sounds ideal, but i have not found a way to pass the user selected
> file into the loop that writes the data without opening another file.

Don;t pass the file pass the fgile *name*
Then inside the update method open the file(in append mode)
and write the latest update then close the file again. (Or
use the 'with' paradigm which closes the file for you)
Repeat as needed.

Part of the propblem is that you are openming the file right
at the beginning and trying to pass the open file object
around. Pass the filename and open when needed. Its slightly
more resource intensive but a lot simpler.

> how would i use shutil to copy the tempory self.logfile into the user
> selected file in this open fileFile()?:

The way to go is to only have one file and avoid all the
copying stuff completely.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list