Hi
I have a code to read the csv file
import csv
d = csv.reader(open('C:/Documents and Settings/242481/My Documents/file.csv'))
for row in d:
print row
This code returns all the rows in the csv file
Is there any way i can read one row at a time.
And each time i execute the print line i need to get the next row.
Thanks in advance
Aadith
it should work the way you have it, but maybe the EOL characters are not what is expected for the system you’re on. try opening it with ‘rU’: open(‘file.csv’, ‘rU’)
to verify that it’s printing one row at a time, you could print a blank line between rows:
or pause it:
for row in d: print row raw_input('continue-> ')For your other code, it should be something like:
Always close your open files. It’s good practice, even though not always strictly necessary. And ‘file’ is a Python class name. Although you can use these any way you wish, doing so can lead to hard-to-find bugs later on.