How to get a reference to current module's attributes in Python

前端 未结 3 404
梦毁少年i
梦毁少年i 2020-11-28 04:02

What I\'m trying to do would look like this in the command line:

>>> import mymodule
>>> names = dir(mymodule)

How can I

3条回答
  •  感动是毒
    2020-11-28 04:44

    Just use globals()

    globals() — Return a dictionary representing the current global symbol table. This is always the dictionary of the current module (inside a function or method, this is the module where it is defined, not the module from which it is called).

    http://docs.python.org/library/functions.html#globals

提交回复
热议问题