list of methods for python shell?

后端 未结 9 1401
鱼传尺愫
鱼传尺愫 2021-02-13 21:27

You\'d have already found out by my usage of terminology that I\'m a python n00b.

straight forward question:

How can i see a list of methods for a particular obj

9条回答
  •  情歌与酒
    2021-02-13 22:08

    Others have mentioned dir. Let me make an remark of caution: Python objects may have a __getattr__ method defined which is called when one attempts to call an undefined method on said object. Obviously dir does not list all those (infinitely many) method names. Some libraries make explicit use of this feature, e.g. PLY (Python Lex-Yacc).

    Example:

    >>> class Test:
    ...     def __getattr__(self, name):
    ...         return 'foo <%s>' % name
    ...
    >>> t = Test()
    >>> t.bar
    'foo '
    >>> 'bar' in dir(t)
    False
    

提交回复
热议问题