Convert python filenames to unicode

后端 未结 6 1164
星月不相逢
星月不相逢 2020-12-16 13:13

I am on python 2.6 for Windows.

I use os.walk to read a file tree. Files may have non-7-bit characters (German \"ae\" for example) in their filenames. These are enco

6条回答
  •  一个人的身影
    2020-12-16 14:06

    If you pass a Unicode string to os.walk(), you'll get Unicode results:

    >>> list(os.walk(r'C:\example'))          # Passing an ASCII string
    [('C:\\example', [], ['file.txt'])]
    >>> 
    >>> list(os.walk(ur'C:\example'))        # Passing a Unicode string
    [(u'C:\\example', [], [u'file.txt'])]
    

提交回复
热议问题