python-3.x - 非常具体的输出格式 Python
问题描述
我想弄清楚如何在终端中具体打印如下:
然后将其写入 .txt 文件。
我的尝试:
我使用“制表”已经有一段时间了,所以我自然而然地尝试使用这个库。这是我的代码:
from tabulate import tabulate
import numpy as np
lista = np.zeros(4)
print(tabulate([lista, lista], headers=['n', r'$\phi_{n}$', 'a_{n}', 'e_{n}'],
numalign="center"))
with open('table.txt', 'w') as f:
f.write(tabulate([lista, lista], headers=['n', r'$\phi_{n}$', 'a_{n}', 'e_{n}'], numalign="center"))
上面的代码生成以下结果:
这很好,但不是我想要的。我试图删除“标题”参数,但它仍然给了我一个包含标题结构的表。此外,它不包含我需要的 '&' 字符和 '\' 的东西。我怀疑我可能需要以某种方式手动完成。
在此先感谢,卢卡斯
解决方案
推荐阅读
- r - 用选定的平均值和标准差缩放向量
- android - Firebase 谷歌登录失败
- c++ - 通过 intmax 有效划分 int
- elasticsearch - elasticsearch中文本数据类型的ignore_above
- javascript - 如何使用javascript在元素中显示图像?
- java - 如何在 Java 中将 JMSBytesMessage 转换为 TextMessage
- mongodb - 为什么 mongodb upsert 计数器不反映实际变化?
- javascript - 我无法正确创建别名
- python - 在python中读取和解释混合的二进制和文本文件
- r - 无法使用多个 geom_point 和 geom_smooth 指定颜色