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"))
精彩评论