append log file

Gary Herron gherron at islandtraining.com
Mon Sep 29 22:10:57 CEST 2003


On Monday 29 September 2003 12:53 pm, Tom wrote:
> Hi,
> I have a log file and of course I want to add the new information to the
> end of that log file. Unfortunately I always delete the old information
> and only append the current info.
>
> Right now I do it like this:
> I call a module which consists of a class and a function. It actually
> doesn't matter, but I just included it for the sake of completeness.
> The module looks like this:
>
> class log_C:
>     def errorlog(self, filename, Data, d):
>         LogFile = file(filename, 'w')
>         ErrorInfo = Data[d+1]
>         LogFile.write(ErrorInfo)
>         LogFile.close()
>
> How can I add the new info without deleting the old info?
> I tried the modes 'a' and 'a+' but they both didn't work. Actually the
> data was totally unreadable! It was kind of messed up. :-( I don't know
> why.

Well ... A mode of "a" is the correct thing, abd it works just fine
for me.  So we need to know some other things to solve this problem.

What platform?

Is the data ascii or binary? (If binary on win32, then you probably
need mode "ab" or some such)

Exactly what do you mean by "messed up"?  

Gary Herron







More information about the Python-list mailing list