471,337 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

CSV Issues

Hello,
I'm working on a script which collects some data and puts into a csv
file which could be exported to excel.
so far so good, I'm able to do what I described.
When I run the script for the second time after a certain period of
time the results should appear next to the results of the last run,
I'm unable to make a new column when the script is run after the first
time.
Ideally I would like to have an output which looks like this.
1/20 1/27
we.py we.py
gh.py gj.py <- Indicating tht the file has changed
fg.py fg.py

Please help me out.
Thanks

Jul 19 '07 #1
1 912
Hi,

On Thu, 19 Jul 2007 06:59:24 +0200, Rohan <vo********@gmail.comwrote:
When I run the script for the second time after a certain period of
time the results should appear next to the results of the last run,
I'm unable to make a new column when the script is run after the first
time.
Ideally I would like to have an output which looks like this.
1/20 1/27
we.py we.py
gh.py gj.py <- Indicating tht the file has changed
fg.py fg.py
Try something like this:
>>import csv
f = open("/tmp/data.csv", "rb")
reader = csv.reader(f)
headings = reader.next()
headings
['1/20']
>>rows = []
for row in reader:
.... rows.append(row)
....
>>rows
[['we.py'], ['gh.py'], ['fg.py']]
>>f.close()
headings.append("1/27")
rows[0].append("we.py")
rows[1].append("gj.py")
rows[2].append("fg.py")
f = open("/tmp/data.csv", "wb")
writer = csv.writer(f)
writer.writerow(headings)
writer.writerows(rows)
f.close()
Regards
Lutz
Jul 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

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.