2

我正在解析一个文本文件并将我需要的信息提取到一个漂亮的表格中。但是,我无法将表格写成一个表格,它输出为每个项目的单个表格。

我输出表格的代码:

f = open("out2.txt", "w")
for item in table:
    f.write("%s\n" % item)

f.write("There are %(count)d errors found" %{"count": count})

我的输出看起来像:

在此处输入图像描述

我怎样才能写出表格,使其成为一个连续的表格?

4

1 回答 1

1

对你有用f.write(table.get_string())吗?而不是遍历表并编写每个项目,只需编写表本身?

所以像这样,替换循环:

f = open('out2.txt','wb')
f.write(table.get_string())
f.write('There are %(count)d errors found' % {'count': count})
于 2017-10-03T19:23:46.560 回答