Reputation: 5049
I have a particular problem I'm facing with windows file paths in Jupyter notebook.
path = 'C:\apps\python'
print(path)
This gives C:pps\python
What I want to eventually do is to get a reference to the files in path
I was intending to do the following
files = [f for f in listdir(path) if isfile(join(path, f))]
# do something with the list of files
However this throws up the error - OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\x07pps\\python'
Upvotes: 0
Views: 5210
Reputation: 10403
It's because \a
is detected like a special character (like \n
or \t
).
The easiest way to fix your issue here is to use raw strings:
print(r'C:\apps\python')
Gives
C:\apps\python
You can parse a literal string to a raw string with:
path = r'{}'.format(path)
Upvotes: 2