Error with double backslash in Windows path in Python

后端 未结 2 560
清歌不尽
清歌不尽 2020-12-11 06:06

I want to work with paths in Windows in Python 3.3, but I have an error:

FileNotFoundError: [Errno 2] No such file or directory: \'E:\\\\dir\\\\.

2条回答
  •  孤街浪徒
    2020-12-11 06:47

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

提交回复
热议问题