Skip to content

Instantly share code, notes, and snippets.

@st4lk
Created October 22, 2012 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save st4lk/3931305 to your computer and use it in GitHub Desktop.
Save st4lk/3931305 to your computer and use it in GitHub Desktop.
Python: Get csv lines
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