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 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/
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/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |