我想用「open」()函數在python中以「w」模式打開文件。如何使用python中的中文名稱打開文件
文件名是:仿宋人筆意.jpg。
打開的函數失敗,此文件名但成功與普通文件。
如何打開一個名稱不是英文的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")
我總是得到「錯誤打開文件」對非英語文件名。
在此先感謝。
你試過codecs.open()嗎? – Robus 2011-03-17 08:02:50
@Robus:不,我還沒有嘗試過codecs.open()。任何想法如何使用它。我可以谷歌,但如果你能回答,那麼它會節省我的時間。 – 2011-03-17 08:06:30