Created
May 15, 2012 12:32
-
-
Save infyloop/2701404 to your computer and use it in GitHub Desktop.
helps to read a csv file in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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