Python os.walk不';无法正确使用路径中的unicode字符

Python os.walk不';无法正确使用路径中的unicode字符,python,windows,python-2.7,unicode,encoding,Python,Windows,Python 2.7,Unicode,Encoding,我想遍历目录,其中子目录的名称中可以包含非ascii字符。在这种情况下,os.walk将子目录视为一个文件。举例如下: 我有目录test和子目录:asd,géocello for root, dirs, files in os.walk(directory): print(root, dirs, files) 印刷品: test ['asd'] ['geocello'] test\asd [] ['testfile.txt', '123.txt'] 我在Windows XP下运行此代

我想遍历目录,其中子目录的名称中可以包含非ascii字符。在这种情况下,
os.walk
将子目录视为一个文件。举例如下:

我有目录
test
和子目录:
asd
géocello

for root, dirs, files in os.walk(directory):
    print(root, dirs, files)
印刷品:

test ['asd'] ['geocello']
test\asd [] ['testfile.txt', '123.txt']
我在Windows XP下运行此代码。在Linux上,一切都很好。 如何使Python正确使用路径?

目录
传递unicode值:

directory = u'C:/path/to/root'
现在
os.walk()
将在整个过程中使用unicode路径,Windows将正确处理
géocello
文件夹的测试

请注意,在这种情况下,
root
以及
dirs
文件
列表中的值也将是Unicode