Reputation: 327
I have two python files:
AAA.py
def func1():
print('func1')
def func2():
eval('func1')()
print('func2')
BBB.py
from AAA import func2
func2()
In BBB.py, I am not doing "from AAA import *", only func2 got imported, how could python load func1, what's happening behind the scenes?
Upvotes: 0
Views: 231
Reputation: 54718
from AAA import func2
is essentially the same as
import AAA
func2 = AAA.func2
Python has to interpret the entire file in order to find the functions you want.
Upvotes: 2