473,466 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

write to log file

Tom
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.

Thanks for your help.
Regards, Tom

Jul 18 '05 #1
2 6555
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.


The following works for me:
f = open('c:/temp/test.txt', 'w')
for x in ('fee', 'fi', 'fum', 'fo'): .... print >> f, x
.... f.close()
g = open('c:/temp/test.txt', 'a+r')
print >> g, 'slag-blah'
g.close()
file('c:/temp/test.txt').readlines()

['fee\n', 'fi\n', 'fum\n', 'fo\n', 'slag-blah\n']

HTH,

--
Hans (ha**@zephyrfalcon.org)
http://zephyrfalcon.org/

Jul 18 '05 #2
I wrote:
>>> g = open('c:/temp/test.txt', 'a+r')


Then again, using 'a' or 'a+' should work too...

--
Hans (ha**@zephyrfalcon.org)
http://zephyrfalcon.org/

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ellixis | last post by:
Hello, How can I use fwrite() and fseek() in order to write data in the middle (or anywhere else) of a file without overwriting existing data ? People told me that I should load the file into...
5
by: Just Me | last post by:
Using streams how do I write and then read a set of variables? For example, suppose I want to write into a text file: string1,string2,string3 Then read them later. Suppose I want to write...
6
by: sambuela | last post by:
How can I write message to the file located in the wwwroot directory? It seems that IIS protect these files. Let make me cannot do the I/O writing sucessfully. I try to open file's write...
2
by: ykgoh | last post by:
Hi. I've a problem of being able to create and remove a directory but unable to write a file inside the created directory for some strange reason. I suspect that this problem could be vaguely...
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
1
by: =?Utf-8?B?R2FuZXNoIE11dGh1dmVsdQ==?= | last post by:
Hello All, Our application write logs to a file in a folder. Before our application starts writing to that file, I want to check if the current user has write access to that file, for example,...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
6
by: globalrev | last post by:
i ahve a program that takes certain textsnippets out of one file and inserts them into another. problem is it jsut overwrites the first riow every time. i want to insert every new piece of...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.