python - 查找使用“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()
解决方案
尝试这个:
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 *
推荐阅读
- python - 在 anaconda 中安装 wolframalpha 库
- reactjs - react-bootstrap NavBar 未按预期工作
- html - 如何删除/禁用图像样式中的新背景图像过渡?
- nginx - 无法挂载自定义 conf 文件
- python - Python 使用 TCPS 连接到 Oracle 数据库
- python - 刮谷歌地图审查一家公司的文本数据
- python - 使用正则表达式模式提取所需的字符串?
- python - 来自查询集的 Django 模型实例未在 save() 上更新
- arrays - 数组分区 I(如何用数学证明这一点)
- c# - Xamarin 旋转使用相机捕获的图像