【发布时间】:2022-01-27 04:36:57
【问题描述】:
如果这个问题之前被问过,我们深表歉意。 我正在尝试创建一个函数,该函数使用参数 func (要执行的函数)和 args (函数的参数)返回另一个函数的输出。 恼人的是,我不断收到错误消息。
TypeError: execute() missing 1 required positional argument: 'args'
我不确定问题是什么,因为我看不到定义或函数调用有任何错误。如果有帮助,这里是定义;
def execute(func, args):
return func(args)
还有我调用函数的那一行:
print(function)
print(argument)
execute((function, argument))
完整的输出是:
print
Hello world
Traceback (most recent call last):
File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in
cli.main()
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "C:\Python39\lib\runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Python39\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\willd\source\repos\code executer\code_executer.py", line 52, in
execute((function, argument))
TypeError: execute() missing 1 required positional argument: 'args'
如果有帮助,我正在使用 Microsoft Visual Studio 2019 社区。 提前谢谢!
-
执行(函数,参数)
-
(function, argument)
是一回事 - 一个有两个值的元组。