【发布时间】:2016-02-04 14:35:01
【问题描述】:
我有一个打印出目录结构的小程序。 它工作正常,除非目录名称包含德语变音符号。 在这种情况下,int 在目录行之后打印一个空行。
我在 Windows 7 64 位上运行 Python 3.50。
此代码...
class dm():
...
def print(self, rootdir=None, depth=0):
if rootdir is None:
rootdir = self.initialdir
if rootdir in self.dirtree:
print('{}{} ({} files)'.format(' '*depth,
rootdir,
len(self.dirtree[rootdir]['files'])))
for _dir in self.dirtree[rootdir]['dirs']:
self.print(os.path.join(rootdir, _dir), depth+1)
else:
pass
...产生以下输出:
B:\scratch (11 files)
B:\scratch\Test1 (3 files)
B:\scratch\Test1 - Kopie (0 files)
B:\scratch\Test1 - Übel (0 files)
B:\scratch\Test2 (3 files)
B:\scratch\Test2\Test21 (0 files)
代码页设置为 65001 时也是如此。如果我将代码页更改为例如850 然后空白行消失,但“Ü”当然没有正确打印。
结构 self.dirtree 是列表的字典,用 os.walk 解析,看起来没问题。
Python 还是 Windows?有什么建议吗?
马文
【问题讨论】:
标签: windows python-3.x