[Tutor] python 2.4 reading files - unexpected behaviour

John Gerdeman johnpatrick at gerdeman.de
Fri Nov 23 18:06:38 CET 2007


Hello, 

I got a csv file, in which I have to count the occurrences of certain
numbers in columns. I can do this for one arbitrary column, but not for
all.

The problem I encountered is as follows. Iterating through the rows of a
file works, but as soon as I try to iterate through the same file again,
it seems it returns nothing.

Code-example
------------
import csv
file = csv.reader(open("some.csv", "rb"))
for i in file:
	print i

for i in file:
	print i

some.csv:
3, 4, 5
4, 3, 2

The above program only returns:
['3', ' 4', ' 5']
['4', ' 3', ' 2']

instead of:
['3', ' 4', ' 5']
['4', ' 3', ' 2']
['3', ' 4', ' 5']
['4', ' 3', ' 2']

Any help would be welcome.

John
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20071123/dfd4b46c/attachment.pgp 


More information about the Tutor mailing list