Kar*_*n S 5 python windows unicode python-2.7
Python版本:2.7.3
文件名:测试雪人字符--?--.mp3
进行了以下测试,没有一个被证明是成功的。
>>> os.path.exist('test snowman character --?--.mp3')
False
>>> os.path.exist(repr('test snowman character --?--.mp3'))
False
>>> os.path.isfile('test snowman character --\\xe2\\x98\\x83--.mp3')
False
>>> os.path.isfile(r'test snowman character --\\xe2\\x98\\x83--.mp3')
False
>>> os.path.isfile('test snowman character --?--.mp3'.decode('utf-8'))
False
Run Code Online (Sandbox Code Playgroud)
尝试使用 glob 检索文件,即使该测试失败。
目的是检测此文件并将其复制到另一个文件夹中,请指教。
文字 Unicode 字符串应该以 开头u\',尝试一下os.path.exist(u\'test snowman character --\xe2\x98\x83--.mp3\')
如果你想使用转义序列ur\',就像os.path.isfile(ur\'test snowman character --\\\\xe2\\\\x98\\\\x83--.mp3\')
http://docs.python.org/2.7/reference/lexical_analysis.html#strings
\n