Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash有$@和$*。python是否有一个等价的?_Python - Fatal编程技术网

Bash有$@和$*。python是否有一个等价的?

Bash有$@和$*。python是否有一个等价的?,python,Python,在bash中,可以使用$@或$*获取函数/方法的参数列表作为列表。python有类似的功能吗?我正在尝试做一种日志记录,其中函数的日志将打印出函数参数 范例 def foo(a:str,b:List) 打印(magic_get_args_function()); .... foo(“h”[1,2,3]) 输出 h、[1、2、3]#甚至可能包括参数名称 这个怎么样 从检查导入getcallargs def foo(a:str,b:list): 打印(getcallargs(foo,a,b)) f

在bash中,可以使用$@或$*获取函数/方法的参数列表作为列表。python有类似的功能吗?我正在尝试做一种日志记录,其中函数的日志将打印出函数参数

范例

def foo(a:str,b:List)
打印(magic_get_args_function());
....
foo(“h”[1,2,3])
输出

h、[1、2、3]#甚至可能包括参数名称
这个怎么样

从检查导入getcallargs
def foo(a:str,b:list):
打印(getcallargs(foo,a,b))
foo(“h”[1,2,3])
{'a':'h','b':[1,2,3]}
这个怎么样

从检查导入getcallargs
def foo(a:str,b:list):
打印(getcallargs(foo,a,b))
foo(“h”[1,2,3])
{'a':'h','b':[1,2,3]}

旁白:$*不会像这个问题的第一句所说的那样,以列表形式返回参数;它将它们强制为一个字符串(如果使用该字符串,则该字符串将被拆分回一个列表并进行glob扩展,但不能保证与原始参数列表相同)。始终使用
“$@”
(带引号)。@CharlesDuffy感谢您的澄清:
$*
不会像问题的第一句所说的那样以列表形式返回参数;它将它们强制为一个字符串(如果使用该字符串,则该字符串将被拆分回一个列表并进行glob扩展,但不能保证与原始参数列表相同)。始终使用
“$@”
(带引号)代替。@charlesduff感谢您的澄清