How to get a list of variables in specific Python module?

前端 未结 5 818
野趣味
野趣味 2020-11-30 10:42

Let\'s assume I have the following file structure:

data.py

foo = []
bar = []
abc = \"def\"

core.py

5条回答
  •  伪装坚强ぢ
    2020-11-30 11:27

    I have to make a dictionary of these variables. I used this code.

    print({item:getattr(my_module, item) for item in dir(my_module) if not item.startswith("__") and not item.endswith("__")})
    

提交回复
热议问题