[Tutor] Need help appending data to a logfile

Matt D md123 at nycap.rr.com
Fri Jun 28 14:29:32 CEST 2013


On 06/28/2013 07:37 AM, Dave Angel wrote:
> On 06/28/2013 07:27 AM, Matt D wrote:
>>
>>>
>>> As for the shutil.copy() function, how complex can it be?  It takes two
>>> file names, source and destination.  It does not need a with statement
>>> since it wants strings, not file handles.
>>>
>>> You might get into trouble on some OS's with the source file already
>>> open, but since you open it with append, it should be trivial to close
>>> and reopen it.
>>>
>>>
>> The problem here is that the, I am pretty sure that, using anything from
>> shutil overwrite what is currently in the 'dst' file.  So if I am
>> starting and stopping the program, that file is going to lose
>> everything.  There has to be a way around this.
> 
> 
> And that's exactly what Save-As is supposed to do.  If you want
> something different, you might have said so.
> 
> 
Right.
I am thinking something like this: opening the logfile.txt in 'w' so
that can overwrite each time the program is run and that data will only
be what has been logged in that run.  And open the 'mypath' in 'a' and
somehow append whats in 'logfile' into 'mypath'.
I have been unable to find any sort of example of this.


More information about the Tutor mailing list