How to get the list of all initialized objects and function definitions alive in python?

前端 未结 4 1769
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 01:09

Say that in the python shell (IDLE) I have defined some classes, functions, variables. Also created objects of the classes. Then I deleted some of the objects and created so

4条回答
  •  不思量自难忘°
    2020-12-29 02:05

    Yes.

    >>> import gc
    >>> gc.get_objects()
    

    Not that you'll find that useful. There is a lot of them. :-) Over 4000 just when you start Python.

    Possibly a bit more useful is all the variables active locally:

    >>> locals()
    

    And the one active globally:

    >>> globals()
    

    (Note that "globally" in Python isn't really global as such. For that, you need the gc.get_objects() above, and that you are unlikely to ever find useful, as mentioned).

提交回复
热议问题