[英]TypeError: 'headers' is an invalid keyword argument for print()
I recently installed tabulate onto conda and I am trying to tabulate my results with print syntax Source: Printing Lists as Tabular Data but I am getting "TypeError: 'headers' is an invalid keyword argument for print()" 我最近在conda上安装了表格,我试图用打印语法将结果列表来源: 打印列表作为表格数据,但我得到“TypeError:'headers'是print()的无效关键字参数”
I have tried "print(tabulate([['Alice', 24], ['Bob', 19]], headers=['Name', 'Age'], tablefmt='orgtbl'))" 我试过“print(tabulate([['Alice',24],['Bob',19]],headers = ['Name','Age'],tablefmt ='orgtbl'))”
from tabulate import tabulate
i: int
with open("incre.txt", "w") as file:
for i in range(1, 100,5):
mol = int((i*50)/(i+50))
file.write(str(i)+ " " +str(mol) + "\n")
print(tabulate([[i], [mol]]), headers=['i' , 'mol'], tablefmt='orgtbl')
file.close()
Expected Results would be on terms of 预期结果将按照条款进行
I am getting typeerror, what am I missing here? 我得到了类型错误,我在这里错过了什么?
There is a mistake in the way you wrote your parenthesis, try with that line: 您编写括号的方式有误,请尝试使用该行:
print(tabulate([[i], [mol]], headers=['i' , 'mol'], tablefmt='orgtbl'))
What you were doing was like doing this: 你在做什么就像这样做:
x = tabulate([[i], [mol]]
print(x, headers=['i' , 'mol'], tablefmt='orgtbl')
As you can see there, you were trying to call the print
method with headers
and tablefmt
keywords, wich caused the error: 'headers' is an invalid keyword argument for print()
正如你在那里看到的那样,你试图用
headers
和tablefmt
关键字调用print
方法,导致错误: 'headers' is an invalid keyword argument for print()
Update: 更新:
I'm not sure, but i think what you try to achieve is: 我不确定,但我认为你想要达到的目标是:
from tabulate import tabulate
values = []
for i in range(1, 100,5):
mol = int((i*50)/(i+50))
values.append([i, mol])
print(tabulate(values, headers=['i' , 'mol'], tablefmt='orgtbl'))
in your code, you were printing i
and mol
after having exited from the while loop, then you would have only printed their last values... 在你的代码中,你在退出while循环后打印
i
和mol
,那么你只会打印出他们的最后一个值......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.