简体   繁体   English

TypeError:'headers'是print()的无效关键字参数

[英]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() 正如你在那里看到的那样,你试图用headerstablefmt关键字调用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循环后打印imol ,那么你只会打印出他们的最后一个值......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复“ TypeError:sort()的无效关键字参数” - How to fix 'TypeError: invalid keyword argument for sort()' 类型错误:“编码”是此函数的无效关键字参数 - TypeError: 'encoding' is an invalid keyword argument for this function TypeError:'cmp'是此函数的无效关键字参数 - TypeError: 'cmp' is an invalid keyword argument for this function 为什么“轴”是print() 的无效关键字参数? - why 'axis' is an invalid keyword argument for print()? TypeError:urlopen()获得了意外的关键字参数'headers'_Python3 - TypeError: urlopen() got an unexpected keyword argument 'headers'_Python3 int() 的无效关键字参数 - invalid keyword argument for int() “TypeError: __init__() got an unexpected keyword argument 'headers'” 从 tcms_api 导入 TCMS 时出错 - "TypeError: __init__() got an unexpected keyword argument 'headers'" Error when importing TCMS from tcms_api TypeError:('关键字参数不理解:','输入') - TypeError: ('Keyword argument not understood:', 'input') TypeError:'question_text'是Django 2.0教程中此函数的无效关键字参数 - TypeError: 'question_text' is an invalid keyword argument for this function in django 2.0 tutorial TypeError:'utf8' 是 Compat32 smtplib email 错误消息的无效关键字参数 - TypeError: 'utf8' is an invalid keyword argument for Compat32 smtplib email error message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM