且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Python中处理UTF文件名

更新时间:2022-06-18 14:54:36

对于那些对完整解决方案感兴趣的人:

For those interested in the full solution:

dirpath = raw_input()

已更改为:

dirpath = raw_input().decode(sys.stdin.encoding)

这使得传递给os.walk()的参数使用unicode,导致返回的文件名也使用unicode.

That allowed for the argument being passed to os.walk() to be in unicode, causing the filenames it returned to also be in unicode.

要将这些内容写入文件或从文件写入(第二个问题),我使用了codecs.open()功能

To write these to or from a file (my second question) I used the codecs.open() functionality