1

I have a script for importing the contents of csv files in to a database. But when I try

filepath = '/Users/mc_kaiser/Desktop/Foo\ 020218-021318.csv'
test = open(filepath)

I get an IOError:

IOError: [Errno 2] No such file or directory: '/Users/mc_kaiser/Desktop/Foo\\ 020218-021318.csv'

I looked at this SO post and tried some of the answers, but it's Windows specific and didn't answer my question. Thank you!

mc_kaiser
  • 699
  • 7
  • 17
  • Did `filepath = '/Users/mc_kaiser/Desktop/Foo 020218-021318.csv'` not work? (Without the `'\'`) – pault Feb 14 '18 at 20:57

1 Answers1

2

That \ for escape is only used by shell, not part of the file name. In Python, just use:

filepath = '/Users/mc_kaiser/Desktop/Foo 020218-021318.csv'
llllllllll
  • 15,580
  • 4
  • 25
  • 47