我试图在"w"模式下打开一个文件,在python中使用"open()"函数.
文件名是:仿宋人笔意.jpg.
open函数使用此文件名失败,但成功使用普通文件.
如何在python中打开名称不是英文的文件?
我的代码如下:
try:
filename = urllib.quote(filename.encode('utf-8'))
destination = open(filename, 'w')
yield("<br>Obtained the file reference")
except:
yield("<br>Error while opening the file")
Run Code Online (Sandbox Code Playgroud)
对于非英文文件名,我总是得到"打开文件时出错".
提前致谢.
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import codecs
f=codecs.open(u'?????.txt','r','utf-8')
print f.read()
f.close()
Run Code Online (Sandbox Code Playgroud)
在这里工作得很好