在 python 中在输出文件中写入 prettytable
Writing prettytable in output file in python
我正在解析一个文本文件并将我需要的信息提取到一个漂亮的文件中table。但是,我无法将 table 写成一个 table 它输出为每个项目的单个 table 。
我的输出代码 table:
f = open("out2.txt", "w")
for item in table:
f.write("%s\n" % item)
f.write("There are %(count)d errors found" %{"count": count})
我的输出如下:
我怎样才能写出 table 使其成为一个连续的 table?
f.write(table.get_string())
对你有用吗?而不是遍历 table 并编写每个项目,只需编写 table 本身?
所以像这样,替换循环:
f = open('out2.txt','wb')
f.write(table.get_string())
f.write('There are %(count)d errors found' % {'count': count})
我正在解析一个文本文件并将我需要的信息提取到一个漂亮的文件中table。但是,我无法将 table 写成一个 table 它输出为每个项目的单个 table 。
我的输出代码 table:
f = open("out2.txt", "w")
for item in table:
f.write("%s\n" % item)
f.write("There are %(count)d errors found" %{"count": count})
我的输出如下:
我怎样才能写出 table 使其成为一个连续的 table?
f.write(table.get_string())
对你有用吗?而不是遍历 table 并编写每个项目,只需编写 table 本身?
所以像这样,替换循环:
f = open('out2.txt','wb')
f.write(table.get_string())
f.write('There are %(count)d errors found' % {'count': count})