我需要能够读取或重命名包含字符:€ 的文件。 这个角色有一个我用 a 得到的随机位置。我该怎么做?
import os
os.rename("C:\\Python2\\"+u"€.txt","test.txt")
发给我:
Traceback (most recent call last):
File "test.py", line 21, in <module>
os.rename("C:\\Python2\\"+u"Ôé¼.txt","test.txt")
最佳答案
使用str.decode
方法:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
os.rename("C:/Python2/€.txt".decode('UTF-8'),"test.txt")
关于文件名中的 Python €,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43501482/