考虑一下
# file1.py
file1_variable = "something"
import file2
# file2.py
print(file1_variable)
这可能吗?如果是,怎么做?
显然globals
和locals
file2.py
不包含file1.py
个变量
高级示例我的目标是:
文件结构:
- file1.py
- my_package/
- __init__.py
# file1.py
file1_variable = "something"
import my_package
# my_package/__init__.py
# Do something to get all variables from file1.py, I dont know what
print(locals()) # Should print file1_variable among others