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

前端 未结 3 403
梦毁少年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 05:00

    As previously mentioned, globals gives you a dictionary as opposed to dir() which gives you a list of the names defined in the module. The way I typically see this done is like this:

    import sys
    dir(sys.modules[__name__])
    

提交回复
热议问题