IOError: [Errno 22] invalid mode ('rb') or filename: ’\u202a’ / '\xe2\x80\xaa’

p = u‘‘ + r‘?C:\Users\Administrator\Desktop\222.txt‘

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

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

 

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

‘\xe2\x80\xaa‘.decode(‘utf-8‘)
Out: u‘\u202a‘

也是它

去掉行不行呢?

 

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

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

 

 

but.....

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

技术分享

 

 

 

但是,另外再开一个ipython

技术分享

大写盘符路径又正常了? 

懵逼-_-

Windows下python 薛定谔的路径?

文章来自:http://www.cnblogs.com/willowj/p/7414801.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3