Assume having a directory structure like this:
src\
foo1.py
Dir\
foo2.py
When I use the below code inside foo1.py, I have no problem in running:
import os
os.chdir("Dir")
exec(open("./foo2.py").read())
os.chdir("..")
But when I changed it to this:
import os
def test():
os.chdir("Dir")
exec(open("./foo2.py").read())
os.chdir("..")
test()
Error accurs:
Traceback (most recent call last):
File "foo1.py", line 8, in <module>
test()
File "foo1.py", line 5, in test
exec(open("./foo2.py").read())
File "<string>", line 134, in <module>
NameError: name 'resistorLength' is not defined
Anything I am missing?
Thank you.