开发者

Python, Linux: How to delete unicode files?

I have a file whose name contains accents.

I'm trying to use Python's os.remove to delete it, but I keep getting an UnicodeDecodeError.

I'm using Ubuntu, Python 2.6 and 开发者_如何学JAVAmy locale LANG=en_US.utf-8

Thanks.


There are no "unicode files" in Linux. Encode your unicode with the encoding used by the filesystem.


I'm guessing you are doing this:

os.unlink(u"Thé file näme.dôc")

Try this instead:

os.unlink(u"Thé file näme.dôc".encode("utf8"))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜