How do I look inside a Python object?

后端 未结 22 1645
感情败类
感情败类 2020-12-04 04:18

I\'m starting to code in various projects using Python (including Django web development and Panda3D game development).

To help me understand what\'s going on, I wo

22条回答
  •  [愿得一人]
    2020-12-04 05:00

    You can list the attributes of a object with dir() in the shell:

    >>> dir(object())
    ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
    

    Of course, there is also the inspect module: http://docs.python.org/library/inspect.html#module-inspect

提交回复
热议问题