Reputation: 11
I am getting this error when trying to print the contents of a CSV file in Python.
Traceback (most recent call last): File "/Users/cassandracampbell/Library/Preferences/PyCharmCE2018.2/scratches/Player.py", line 5, in with open('player.csv') as csvfile: FileNotFoundError: [Errno 2] No such file or directory: 'player.csv'
Upvotes: 0
Views: 185
Reputation: 28
Check that you have the file in question in same directory as your .py file you're working on. If that doesn't work you might want to use the full path to the file:
with open ('/Users/cassandracampbell/Library/Preferences/PyCharmCE2018.2/scratches/player.CSV') as csvfile:
And you should try to check the name of the file too should be case sensitive otherwise, let's say you have Player.csv then don't try to open player.csv all lower case won't work!
Plus I don't know what you're trying to do with your CSV file, just print the raw content? You might like using pandas.
Upvotes: 0
Reputation: 1083
Get the exact file path to the csv, if you are on a windows get the entire folder path and then the name, and then do:
with open(r'C:\users\path\players.csv') as csvfile:
If you're using a windows and the exact path, easiest to put the r
before the path like I did because it is a literal which will allow the string to be interpreted and the path to be found.
Upvotes: 1
Reputation: 1083
You must put player.csv
to the same location with your script Player.py
Example like your code, both files should be here: /Users/cassandracampbell/Library/Preferences/PyCharmCE2018.2/scratches/
Or you can put the specific directory of player.csv
,
Ex:
with open("/Users/cassandracampbell/Library/Preferences/PyCharmCE2018.2/scratches/player.csv") as csvfile:
...
Upvotes: 0