Created
September 20, 2011 16:05
-
-
Save mark-kubacki/1229520 to your computer and use it in GitHub Desktop.
Beispiel: CSV Dateien einlesen
This file contains 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
import csv | |
__all__ = ['read_csv_file'] | |
def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs): | |
csv_reader = csv.reader(utf8_data, dialect=dialect, **kwargs) | |
for row in csv_reader: | |
yield [unicode(cell, 'utf-8', errors='ignore') for cell in row] | |
def read_csv_file(filename): | |
with open(filename) as csv_file: | |
reader = unicode_csv_reader(csv_file) | |
# first row contains column titles | |
column_titles = reader.next() | |
# subsequent rows contain data | |
for row in reader: | |
yield dict(zip(column_titles, row)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ferner: