Skip to content

Instantly share code, notes, and snippets.

@ivanelson
Created April 23, 2013 19:45
Show Gist options
  • Save ivanelson/5446783 to your computer and use it in GitHub Desktop.
Save ivanelson/5446783 to your computer and use it in GitHub Desktop.
Read files CSV with column named.
#!/usr/bin/env python
#-*- encoding: utf-8 -*-
# By Ivan
import sys, csv
from decimal import Decimal
from datetime import datetime
def csv_columnames():
data = csv.reader(open('entgara.csv'), delimiter=';')
#Read the column names from the first line of the file
fields = data.next()
for row in data:
# Zip together the field names and values
items = zip(fields, row)
item = {}
print items
# Add the value to our dictionary
for (name, value) in items:
item[name] = value.strip()
print 'Coluna: ',name
print 'Valor: ', value
print item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment