Zziggurats
Zziggurats

Reputation: 175

Little trouble in open files using python in Mac os

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

Upvotes: 0

Views: 144

Answers (1)

mgilson
mgilson

Reputation: 309841

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 :-)

Upvotes: 3

Related Questions