Created
December 10, 2014 17:17
-
-
Save ikks/4b94c48a624d93d1e532 to your computer and use it in GitHub Desktop.
Load a unicode csv file from an url
This file contains hidden or 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 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