Skip to content

Instantly share code, notes, and snippets.

@infyloop
Created May 15, 2012 12:32
Show Gist options
  • Save infyloop/2701404 to your computer and use it in GitHub Desktop.
Save infyloop/2701404 to your computer and use it in GitHub Desktop.
helps to read a csv file in python
myfile = open("../myfile.csv", "rb")
reader = csv.reader(myfile)
for row in reader:
if rownum == 0:
header = row
# depending upon the format of the csv file you might have to split things as well, if the file is not formatted properly, which generally is the case.
else:
colnum = 0
for col in row:
print "%-8s: %s" % (header[colnum], col)
colnum += 1
rownum += 1
ifile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment