inspect.getargvalues returns 仅关键字 args 作为 args 而不是 varargs
inspect.getargvalues returns keyword only args as args instead of varargs
如何解释 inspect.getargvalues
returns 关键字仅将 args 作为 args 而不是 varargs。这是错误还是文档错误?仅关键字参数不是关键字参数吗?没看懂。
inspect.getargvalues(frame)
Get information about arguments passed into a particular frame. A named tuple ArgInfo(args, varargs, keywords, locals) is returned. args
is a list of the argument names. varargs and keywords are the names of
the * and ** arguments or None. locals is the locals dictionary of the
given frame.
import inspect
def fun(x, *, y):
print (inspect.getargvalues(inspect.currentframe()))
输出:
fun (10, y=20)
ArgInfo(args=['x', 'y'], varargs=None, keywords=None, locals={'y': 20, 'x': 10})
正如它所说:“可变参数和关键字是 * 和 ** 参数的名称”。您的函数没有任何 *
或 **
参数。
这里出现的*
:
def fun(x, *, y):
仅用作位置参数和仅关键字参数之间的分隔符。
这将是一个函数示例,其中将设置 varargs
和 keywords
:
def fun(*x, **y):
print(inspect.getargvalues(inspect.currentframe()))
这将产生:
>>> fun(10, y=20)
ArgInfo(args=[], varargs='x', keywords='y', locals={'x': (10,), 'y': {'y': 20}})
如何解释 inspect.getargvalues
returns 关键字仅将 args 作为 args 而不是 varargs。这是错误还是文档错误?仅关键字参数不是关键字参数吗?没看懂。
inspect.getargvalues(frame)
Get information about arguments passed into a particular frame. A named tuple ArgInfo(args, varargs, keywords, locals) is returned. args is a list of the argument names. varargs and keywords are the names of the * and ** arguments or None. locals is the locals dictionary of the given frame.
import inspect
def fun(x, *, y):
print (inspect.getargvalues(inspect.currentframe()))
输出:
fun (10, y=20)
ArgInfo(args=['x', 'y'], varargs=None, keywords=None, locals={'y': 20, 'x': 10})
正如它所说:“可变参数和关键字是 * 和 ** 参数的名称”。您的函数没有任何 *
或 **
参数。
这里出现的*
:
def fun(x, *, y):
仅用作位置参数和仅关键字参数之间的分隔符。
这将是一个函数示例,其中将设置 varargs
和 keywords
:
def fun(*x, **y):
print(inspect.getargvalues(inspect.currentframe()))
这将产生:
>>> fun(10, y=20)
ArgInfo(args=[], varargs='x', keywords='y', locals={'x': (10,), 'y': {'y': 20}})