如何在命令提示符下以清晰的格式打印输出

How to print output in a clear format as it gets print on command prompt

感谢您的帮助。

**** 解决了 **** 对于标准输出中的我: 打印 (i)

Stdout 是一个字符串列表 - 遍历它并打印每个字符串而不是打印整个列表。

for i in stdout:
    print(i) # you can add end='' if you want to remopve the double spacing -> print(i, end='')

要写入文件,我建议从 python 关于 reading and writing files

的文档开始

另一种解决方案是:

print(stdout.getvalue())

关于 readlines() 与 getvalue() 的更多解释可以在此 post 中找到: