是否有显示对象规范的Python函数或方法?

mma*_*son 4 python

是否有一种内置的方法可以在Python中获取规范注释,而不是返回并在类定义中读取它们?具体来说,我试图确定导入模块中的对象有多少和哪种参数.

我在Python文档中找不到这个答案,如果已经在这里得到了解答,我就无法在搜索中找到它.

dm0*_*514 6

>>> from random import randint
>>> help(randint)


Help on method randint in module random:

randint(self, a, b) method of random.Random instance
    Return random integer in range [a, b], including both end points.
(END)
Run Code Online (Sandbox Code Playgroud)

http://docs.python.org/2.7/library/functions.html#help

使用自定义类:

>>> class Test(object):
...     def __init__(self, smile):
...             print(smile)
...
>>> help(Test)

Help on class Test in module __main__:

class Test(__builtin__.object)
 |  Methods defined here:
 |  
 |  __init__(self, smile)
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
(END)
Run Code Online (Sandbox Code Playgroud)

  • 如果你使用ipython作为shell:`测试?` (2认同)