You need to replace open
with urllib.urlopen or urllib2.urlopen.
e.g.
import csv import urllib2 url = 'http://winterolympicsmedals.com/medals.csv' response = urllib2.urlopen(url) cr = csv.reader(response) for row in cr: print row
This would output the following
Year,City,Sport,Discipline,NOC,Event,Event gender,Medal 1924,Chamonix,Skating,Figure skating,AUT,individual,M,Silver 1924,Chamonix,Skating,Figure skating,AUT,individual,W,Gold ...
The original question is tagged “python-2.x”, but for a Python 3 implementation (which requires only minor changes) see below.
Related Posts:
- How to import a csv-file into a data array?
- TypeError: list indices must be integers or slices, not str
- What is the difference between rw+ and r+
- Writing a pandas DataFrame to CSV file
- Writing a pandas DataFrame to CSV file
- raw_input function in Python
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- How to use Python to execute a cURL command?
- IndexError: too many indices for array
- How to use Python to execute a cURL command?
- ValueError : I/O operation on closed file
- write() versus writelines() and concatenated strings
- Pandas: ValueError: cannot convert float NaN to integer
- csv.Error: iterator should return strings, not bytes
- No module named MySQLdb
- No module named MySQLdb
- How do you use subprocess.check_output() in Python?
- Python – Reading and writing csv files with utf-8 encoding
- Python Error io.UnsupportedOperation: not readable
- How can I concatenate str and int objects?
- load csv into 2D matrix with numpy for plotting
- Dump a NumPy array into a csv file
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- How to print colored text to the terminal
- How to load a tsv file into a Pandas DataFrame?
- How do you use subprocess.check_output() in Python?
- Difference between writerow() and writerows() methods of Python csv module
- Create a .csv file with values from a Python list
- Convert XML to CSV file
- TypeError: list indices must be integers or slices, not str
- Convert from CSV to array in Python
- ValueError: cannot index with vector containing NA / NaN values
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- How to print colored text to the terminal
- Creating a dictionary from a csv file?
- Python import csv to list
- Python – ‘ascii’ codec can’t decode byte
- How to return dictionary keys as a list in Python?
- ValueError: x and y must be the same size
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 20: ordinal not in range(128)
- OSError: Initializing from file failed on csv in Pandas
- append new row to old csv file python
- tar: Unrecognized archive format error when trying to unpack flower_photos.tgz, TF tutorials on OSX
- Writing a dictionary to a csv file with one line for every ‘key: value’
- How to remove square brackets from list in Python?
- Python CSV error: line contains NULL byte
- Python CSV Error: sequence expected
- AttributeError: ‘float’ object has no attribute ‘split’4
- How to add pandas data to an existing csv file?
- convert csv file to list of dictionaries
- _csv.Error: field larger than field limit (131072)
- TypeError: super() takes at least 1 argument (0 given) error is specific to any python version?
- CSV new-line character seen in unquoted field error
- What exactly do “u” and “r” string flags do, and what are raw string literals?
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- Writing Python lists to columns in csv
- Using print() (the function version) in Python2.x
- Error in Reading a csv file in pandas[CParserError: Error tokenizing data. C error: Buffer overflow caught – possible malformed input file.]
- FileNotFoundError: [Errno 2] No such file or directory [duplicate]
- python capitalize first letter only
- Is there a short contains function for lists?
- ImportError: No module named pandas. Pandas installed pip
- How to Execute a Python Script in Notepad++?
- Convert a tensor to numpy array in Tensorflow?
- How to import the class within the same directory or sub directory?
- Why do I get AttributeError: ‘NoneType’ object has no attribute ‘something’?
- What is __pycache__?
- Permission denied error by installing matplotlib
- Python equivalent of a given wget command
- How to find list intersection?
- Error while Executing jupyter notebook: [Errno 2] No such file or directory
- ValueError: max() arg is an empty sequence
- What is the difference between sparse_categorical_crossentropy and categorical_crossentropy?
- Inverse of a matrix using numpy
- NameError: name ‘self’ is not defined
- gaierror: [Errno 8] nodename nor servname provided, or not known (with macOS Sierra)
- TypeError: can only concatenate list (not “str”) to list
- What’s the idiomatic syntax for prepending to a short python list?
- How to fix “Attempted relative import in non-package” even with __init__.py
- Errno 13 Permission denied Python
- How to get all possible combinations of a list’s elements?
- Converting strings to floats in a DataFrame
- Pylint “unresolved import” error in Visual Studio Code
- Errno 13 Permission denied Python
- ValueError: object too deep for desired array while using convolution
- Python function overloading
- Breaking out of nested loops
- Youtube_dl : ERROR : YouTube said: Unable to extract video data
- How to stop a function
- What is the common header format of Python files?
- How to use cookies in Python Requests
- Checking if a string can be converted to float in Python
- Python conversion from binary string to hexadecimal
- Case insensitive regular expression without re.compile?
- replace characters not working in python [duplicate]
- ElementClickInterceptedException: element click intercepted:
- During handling of the above exception, another exception occurred
- Python Remove last char from string and return it