Skip to content

Instantly share code, notes, and snippets.

@bobofzhang
Last active December 17, 2015 12:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobofzhang/5612065 to your computer and use it in GitHub Desktop.
Save bobofzhang/5612065 to your computer and use it in GitHub Desktop.
read&write csv in python
import csv
ifile = open('test.csv', "rb")
reader = csv.reader(ifile)
rownum = 0
for row in reader:
# Save header row.
if rownum == 0:
header = row
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