【问题标题】:python - where can I look up the arguments of types.FunctionType?python - 我在哪里可以查找 types.FunctionType 的参数?
【发布时间】:2020-12-27 05:05:05
【问题描述】:

我是 Python 新手,想知道在哪里可以找到 types 包中 FunctionType 的所有可用参数?

我可以在这里找到相关的源代码: https://github.com/python/cpython/blob/3.9/Lib/types.py

但我没有找到FunctionType 的明确定义。

【问题讨论】:

  • 输入help(FunctionType)
  • help 是一个很好的方法,但不是当您想以编程方式获取它时。虽然你的答案也是一个解决方案。

标签: python types arguments


【解决方案1】:

使用inspect.getargspec

>>> import inspect
>>> def foobar(foo, bar, baz):
...     return inspect.getargspec(foobar)
... 
>>> foobar(1, 2, 3)
ArgSpec(args=['foo', 'bar', 'baz'], varargs=None, keywords=None, defaults=None)

检查此以供参考:

【讨论】:

    猜你喜欢
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-16
    • 2012-05-30
    相关资源
    最近更新 更多