Re: [Tutor] line number when reading files using csv module

2006-10-30 Thread Kent Johnson
Duncan Gibson wrote: > Duncan Gibson wrote: >>> import csv >>> >>> class MyReader(object): >>> >>> def __init__(self, inputFile): >>> self.reader = csv.reader(inputFile, delimiter=' ') >>> self.lineNumber = 0 >>> >>> def __iter__(self): >>>

Re: [Tutor] line number when reading files using csv module

2006-10-30 Thread Duncan Gibson
Duncan Gibson wrote: > > > > import csv > > > > class MyReader(object): > > > > def __init__(self, inputFile): > > self.reader = csv.reader(inputFile, delimiter=' ') > > self.lineNumber = 0 > > > > def __iter__(self): > > self.

Re: [Tutor] line number when reading files using csv module CORRECTION

2006-10-27 Thread Bob Gailer
Bob Gailer wrote: > Duncan Gibson wrote: > >> [snip] >> > > >> but I would like to record the line number in the file. >> >> > How about using enumerate(): > >> for line_num, data in enumerate(reader): >> # print reader.line_num, data # SHOULD BE: >> print

Re: [Tutor] line number when reading files using csv module

2006-10-27 Thread Bob Gailer
Duncan Gibson wrote: > [snip] > but I would like to record the line number in the file. > How about using enumerate(): > > for line_num, data in enumerate(reader): > print reader.line_num, data > > -- Bob Gailer 510-978-4454 ___ Tu

Re: [Tutor] line number when reading files using csv module

2006-10-27 Thread Bob Gailer
Duncan Gibson wrote: > If I have the following data file, data.csv: > 1 2 3 > 2 3 4 5 > > then I can read it in Python 2.4 on linux using: > > import csv > f = file('data.csv', 'rb') > reader = csv.reader(f) > for data in reader: > print data > > OK, that's all well

Re: [Tutor] line number when reading files using csv module

2006-10-27 Thread Kent Johnson
Duncan Gibson wrote: > > Kent Johnson wrote: >> The line_num attribute is new in Python 2.5. This is a doc bug, >> it should be noted in the description of line_num. > > Is there some way to create a wrapper around a 2.4 csv.reader to > give me pseudo line number handling? I've been experimenting

Re: [Tutor] line number when reading files using csv module

2006-10-27 Thread Duncan Gibson
Kent Johnson wrote: > The line_num attribute is new in Python 2.5. This is a doc bug, > it should be noted in the description of line_num. Is there some way to create a wrapper around a 2.4 csv.reader to give me pseudo line number handling? I've been experimenting with: import csv clas

Re: [Tutor] line number when reading files using csv module

2006-10-27 Thread Kent Johnson
Duncan Gibson wrote: > If I have the following data file, data.csv: > 1 2 3 > 2 3 4 5 > > then I can read it in Python 2.4 on linux using: > > import csv > f = file('data.csv', 'rb') > reader = csv.reader(f) > for data in reader: > print data > > OK, that's all we

Re: [Tutor] line number when reading files using csv module

2006-10-27 Thread Duncan Gibson
On Fri, 27 Oct 2006 11:35:40 +0200 Duncan Gibson <[EMAIL PROTECTED]> wrote: > > If I have the following data file, data.csv: > 1 2 3 > 2 3 4 5 > > then I can read it in Python 2.4 on linux using: > > import csv > f = file('data.csv', 'rb') > reader = csv.reader(f) > for