[Tutor] reading and writing with csv then appending some data to a specific line
pierre cutellic
pierre.cutellic at gmail.com
Sun Nov 4 17:01:51 CET 2007
Hi,
I wrote this script to select some data from a csv file.
Actually it writes it into a file but i would like to append it into an
existing one to a specific line without removing existing code.
does the open('filename.csv','a+') can do that?
here is the existing code:
*import csv
import sys
def rawdata():
rawdata = []
catched = []
f = open('datalisting_000.csv','r')#the file to read to(!same path)
try:
reader = csv.reader(f)
for row in reader:
rawdata.append(row)
finally:
f.close()
del rawdata[0]
for elem in rawdata:
ag = elem[0]
ag.split(";")
catched.append(ag)
return catched
def sendingraw():
ff = open('data.py','w')#the file to write to(!same path)
ff.write(str(rawdata()))
ff.close()
sendingraw()*
Cheers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071104/22aedbfb/attachment.htm
More information about the Tutor
mailing list