Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > CSV Issues

Reply
Thread Tools

CSV Issues

 
 
Rohan
Guest
Posts: n/a
 
      07-19-2007
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

 
Reply With Quote
 
 
 
 
Lutz Horn
Guest
Posts: n/a
 
      07-19-2007
Hi,

On Thu, 19 Jul 2007 06:59:24 +0200, Rohan <> wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to parse a csv...... a csv that has CRLF in the fields sso Java 20 04-26-2009 11:04 AM
read and write csv file using csv module jliu66 Python 0 10-19-2007 03:12 PM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
Re: csv writerow creates double spaced excel csv files Skip Montanaro Python 0 02-13-2004 08:50 PM
csv writerow creates double spaced excel csv files Michal Mikolajczyk Python 0 02-13-2004 08:38 PM



Advertisments