Python inspect.getargspec with built-in function

前端 未结 2 1463
天命终不由人
天命终不由人 2020-12-19 08:16

I\'m trying to figure out the arguments of a method retrieved from a module. I found an inspect module with a handy function, getargspec. It works

2条回答
  •  感动是毒
    2020-12-19 08:49

    You can get the doc string for such functions/methods which nearly always contains the same type of information as getargspec. (I.e. param names, no. of params, optional ones, default values).

    In your example

    import math
    math.sin.__doc__
    

    Gives

    "sin(x)
    
    Return the sine of x (measured in radians)"
    

    Unfortunately there are several different standards in operation. See What is the standard Python docstring format?

    You could detect which of the standards is in use, and then grab the info that way. From the above link it looks like pyment could be helpful in doing just that.

提交回复
热议问题