等价于python中R中的args()

问题描述 投票:-1回答:2

在python中,R中有args()函数的等效项吗?

显示函数参数名称和相应的默认值...

python r
2个回答
0
投票

您可以使用检查模块,这是一个示例:

args()

0
投票

您可能正在寻找>>> import inspect >>> def foo(bar=0): ... pass >>> inspect.getfullargspec(foo) FullArgSpec(args=['bar'], varargs=None, varkw=None, defaults=(0,), kwonlyargs=[], kwonlydefaults=None, annotations={}) 内置功能

help

或者您也可以将其作为字符串获取

>>> help(print)
Help on built-in function print in module builtins:

print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream.

注意

这不会用文档字符串要求功能:

>>> help_print = print.__doc__
>>> print(help_print)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file:  a file-like object (stream); defaults to the current sys.stdout.
sep:   string inserted between values, default a space.
end:   string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
© www.soinside.com 2019 - 2024. All rights reserved.