0

I have a CSV file in Documents , and I want to open it with python2. I run this

print os.getcwd() /Users/baicai

My file in /Users/baicai/Documents/blabla.csv

I run this get error

df= open('/Documents/blabla.csv')

IOError: [Errno 2] No such file or directory: '/Documents/blala.csv'

or this

f=open('/User/baicai/Documents/blabla.csv')

IOError: [Errno 2] No such file or directory: '/User/baicai/Documents/blabla.csv'

How to read? Thanks

1

1 Answer 1

3
df = open('Documents/blabla.csv')  # remove leading /

With the leading /, the operating system thinks you want an absolute path as opposed to a relative path.

or

f=open('/Users/baicai/Documents/blabla.csv')  # Users, not User

This one was just a typo :-)

Sign up to request clarification or add additional context in comments.

1 Comment

Ack! you beat me by 5 seconds. Well played, sir. Well played

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.