显示函数的参数

时间:2018-12-12 10:57:35

标签: python

我想在特定的库中查看函数的参数,例如:

{
"sections": [
   {
       "head": "Section A",
       "sort": 1,
       "section_id": 3,
       "cols": "2",
       "fields": [
           {
               "id": 5,
               "template_id": 2,
               "section_id": 3,
               "label": "A1",
               "itype": "1",
               "idefault": "",
               "ioptions": "",
               "required": "N",
               "ivalids": "0",
               "sort": 1,
               "created_at": "-0001-11-30 00:00:00",
               "updated_at": "2018-09-23 05:32:59",
               "deleted_at": null
           },
           {
               "id": 6,
               "template_id": 2,
               "section_id": 3,
               "label": "A2",
               "itype": "1",
               "idefault": "",
               "ioptions": "",
               "required": "N",
               "ivalids": "0",
               "sort": 1,
               "created_at": "-0001-11-30 00:00:00",
               "updated_at": "2018-09-23 05:32:59",
               "deleted_at": null
           }
       ]
   }
 ]
 }

让我们说lib包含一个带有两个参数的函数import lib :大小和日期。 我想找到一个函数func,这样当我执行类似help的操作时,它就会给我带来类似help(lib.func)的功能。

有什么建议吗?

1 个答案:

答案 0 :(得分:4)

您需要inspect.getfullargspec

  

获取Python函数参数的名称和默认值。返回一个命名的元组:

     

FullArgSpec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations)