Error with double backslash in Windows path in Python

ε祈祈猫儿з 提交于 2019-11-28 12:42:08
iCodez

If you are using a raw-string, then you do not escape backslashes:

f(r'E:\dir')

Of course, this problem (and many others like it) can be solved by simply using forwardslashes in paths:

f('E:/dir')

Changing '\\' for '/' worked for me. I created a directory named 'a' in C:/ for this example.

>>> (Python interpreter)
>>> import os
>>> os.path.isdir('C:/a/)')
>>> True
>>> os.path.isfile('C:/a/)')
>>> False
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!