Skip to content

Instantly share code, notes, and snippets.

@ikks
Created December 10, 2014 17:17
Show Gist options
  • Save ikks/4b94c48a624d93d1e532 to your computer and use it in GitHub Desktop.
Save ikks/4b94c48a624d93d1e532 to your computer and use it in GitHub Desktop.
Load a unicode csv file from an url
import unicodecsv # pip install unicodecsv
import urllib2
def loadfile(url, delimiter=","):
"""Loads a file from a URL (a csv one), separated with delimiter
returns an array with the contents of the file.
"""
reader = unicodecsv.reader(
urllib2.urlopen(url),
encoding='utf-8',
delimiter=delimiter
)
answer = []
for row in reader:
newrow = []
for item in row:
newrow.append(item.strip())
answer.append(newrow)
return answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment