Confused with csv.reader copies

Scott David Daniels Scott.Daniels at Acm.Org
Sat Mar 28 23:43:10 CET 2009


Jeethu Rao wrote:
> Robert Dailey wrote:
>> First, take a look at my example code:
>> -----------------------------------------------------
>> import csv
>>
>> def pass1( reader ):
>>     print reader.next()
>>     print reader.next()
>>
>> def pass2( reader ):
>>     print reader.next()
>>     print reader.next()
>>
>> reader = csv.reader( open( "C:/IT/Method/SpaceImpact/code/tools/
>> ProfileViewer/performance_profile.csv", "rb" ) )
>>
>> pass1( reader )
>> pass2( reader )
>> -----------------------------------------------------
 >> [an implementation using itertools.tee]

Or even:
     source = open("C:/IT/Method/SpaceImpact/code/tools/ProfileViewer/"
                   "performance_profile.csv", "rb")
     pass1(csv.reader(source))
     source.seek(0)
     pass2(csv.reader(source))

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list