Created
October 22, 2012 12:34
-
-
Save st4lk/3931305 to your computer and use it in GitHub Desktop.
Python: Get csv lines
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 | |
import logging | |
def get_csv_lines(file_name, encoding='cp1251'): | |
try: | |
lines = [] | |
with open(file_name, 'rb') as f: | |
reader = csv.reader(f, delimiter=";") | |
for line in reader: | |
decoded_line = [] | |
for col in line: | |
decoded_line.append(col.decode(encoding)) | |
lines.append(decoded_line) | |
return lines | |
except IOError: | |
message = "Input file %s doesn't exists" % file_name | |
print message | |
logging.error(message) | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment