IOError: [Errno 22] invalid mode ('rb') or filename: ’u202a’ / 'xe2x80xaa’

p = u'' + r'‪C:UsersAdministratorDesktop222.txt'

python 读取文件报错:IOError: [Errno 22] invalid mode ('rb') or filename: u'u202aC:\Users\Administrator\Desktop\222.txt'

明明已经 加了r 不转义,还是报错。

仔细看,比正常路径多了 u202a

'xe2x80xaa'.decode('utf-8')
Out: u'u202a'

也是它

去掉行不行呢?

把那几个字符替换掉....

open(u'u202aC:\Users\Administrator\Desktop\222.txt'.replace(u'u202a','') )
Out[32]: <open file u'C:\Users\Administrator\Desktop\222.txt', mode 'r' at 0x0967BF98>

but.....

发现把盘符 改成小写路径正常了,,,又OK了,。

但是,另外再开一个ipython

大写盘符路径又正常了? 

懵逼-_-

Windows下python 薛定谔的路径?

原文地址:https://www.cnblogs.com/willowj/p/7414801.html