【发布时间】:2014-09-23 10:56:56
【问题描述】:
我想浏览子目录可以在名称中包含非 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 正确处理路径?
【问题讨论】:
标签: python windows python-2.7 unicode encoding