[Tutor] how to read from a csv file?
pierre cutellic
pierre.cutellic at gmail.com
Mon Oct 22 18:01:39 CEST 2007
Hi, this is a module i wrote to catch some data from a csv file:
##########
#module csv data reader
# open a csv file and return its data
import csv
import sys
def __init__(self):
rawdata = []
f = open('datalisting_000.csv','r')
try:
reader = csv.reader(f)
for row in reader:
rawdata.append(row)
finally:
f.close()
def rawdata():
return rawdata
if __name__ == "__main__":
print "This is a module. You can't run it directly. Try to import it."
raw_input("\n\nPress any key to exit.")
#########
But when i try to use like:
##########
import csvdatareader
print csvdatareader.rawdata()
##########
It didn't print anything. Where is the mistake?
Cheers.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071022/da91b456/attachment.htm
More information about the Tutor
mailing list