首页 > 解决方案 > 查找使用“from something import *”导入的所有函数

问题描述

有没有办法找到使用星号语法导入的所有内容:

from something import *

理想情况下,我认为有一种方法可以在使用星号语法导入的脚本中找到任何(我认为是类)。也许使用ast模块,我不确定。

因此对于以下代码:

from tkinter import *
from Modules.SelectionWindow import SelectionWindow

if __name__ == "__main__":
    window = Tk()
    data = open("../assets/version.txt" , "r").read()
    window.state("zoomed")
    window.title("Something here | " + data)
    window.iconbitmap("../assets/images/Icon.ico")
    app = SelectionWindow(window)
    window.mainloop()

我们应该能够选择以下内容: TK()

标签: pythonabstract-syntax-tree

解决方案


尝试这个:

before = globals().copy()
from tkinter import *
after = globals().copy()
imported = {}
for key in after.keys():
  if key not in before.keys() and key != "before":
    imported[key] = after[key]

print(imported)

这给了你任何进口的东西from tkinter import *


推荐阅读