开发者

Python, Linux: How to delete unicode files?

开发者 https://www.devze.com 2023-01-30 04:22 出处:网络
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 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

精彩评论

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