关于python编码的一个问题,求高手解释,在此谢过了先
在C盘根目录下新建一文件,名为:新建 Notepad++ Document.txt
在python shell中执行如下:
>>> import os
>>> name1 = "c://新建 Notepad++ Document.txt"
>>> name2 = name1.decode("gb2312").encode("utf-8")
>>> name3 = name1.decode("gb2312")
>>> os.path.exists(name1)
True
>>> os.path.exists(name2)
False
>>> os.path.exists(name3)
True
>>>
想问下:os.path.exists(para)对参数的编码有要求吗?最近在项目中总是被编码的问题困扰,尤其是存在中文字符的情况,求哪位大师帮忙解释下,先谢谢了。
浙公网安备 33010602011771号