[Tutor] Need help appending data to a logfile

Matt D md123 at nycap.rr.com
Fri Jun 28 15:18:56 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.
> 
> 
what if i did some thing like this i saw on stackoverflow:

f = open("bigfile.txt", "w")
for tempfile in tempfiles:
    while True:
        data = tempfile.read(65536)
        if data:
            f.write(data)
        else:
            break

could i make the 'logfile.txt. a tempfile?
and could the f.write be changed to f.append?




More information about the Tutor mailing list