缺少 3 个必需的位置参数 Python [英] Missing 3 required positional arguments Python

查看:89
本文介绍了缺少 3 个必需的位置参数 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对,所以我正在处理一个 python 代码,但我收到了这个类型错误,TypeError: printE() 缺少 3 个必需的位置参数:'emp2'、'emp3' 和 'emp4'"

Right so I'm working on a python code and I get this type error, "TypeError: printE() missing 3 required positional arguments: 'emp2', 'emp3', and 'emp4'"

for emmp in employee:
    print(printE(emmp))

def printE(emp1, emp2, emp3, emp4):

    emp1 = "{}, {}, {}, {}".format(emp1[0], ' '.join(emp1[1:-2]))
    emp2 = "{}, {}, {}, {}".format(emp2[1], ' '.join(emp2[2:-3]))
    emp3 = "{}, {}, {}, {}".format(emp3[2], ' '.join(emp3[3]))
    emp4 = "{}, {}, {}, {}".format(emp4[3], ' '.join(emp4[0:-1]))
    print("{:10s} {:15s} {:5s} {:15s}".format(emp4[0], emp1[1], emp2[2], emp3[3]))

任何形式的帮助将不胜感激!

Any sort of help will be much appreciated!

推荐答案

for emmp in employee:
    print(printE(emmp))

正如你所说的员工是元组

as you say employee is tuple like

案例 1

employee = ('E1','E2'.....)

注意:当你使用 for 循环迭代元组时,它会给你一次使用 E1 或下一次 E2 以此类推

Note: when you iterator over tuple using for loop it gives you single employ E1 or next time E2 so on

并且您的函数 printE 接受四个参数,您可以使用唯一的单个参数E1"或下次使用E2"来调用它.

And your function printE takes four arguments and you call it with the only single argument 'E1' or next time 'E2' so on.

所以它会给你一个错误,即缺少剩余的参数.

So it gives you error that remaining argument are missing.

案例 2

如果员工是元组的元组然后看这个例子

if employee is tuple of tuple then look this example

employee = (('E1',10,"b10",20),('E1',10,"b10",20))

def printE(emp1, emp2, emp3, emp4):
    """ do what ever you want to do with param meters """

    return emp1 ,emp2 ,emp3, emp4

for emmp in employee:
    print(printE(*emmp))

输出

('E1', 10, 'b10', 20)                                                                                                   

('E1', 10, 'b10', 20)                                                                                                   

这篇关于缺少 3 个必需的位置参数 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆