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):
>>>
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.
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
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
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
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
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
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
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