If I want to explain the problem in a simplified way, I have two A.ipynb and B.ipynb files. In file B I call a function from outside of __main__ in file A but I can not access it and give NameError: name 'do' is not defined error.
File A.ipynb:
if __name__ == "__main__":
def do(value):
print(value)
def func(value):
do(value)
File B.ipynb:
import import_ipynb
from A import *
func('some text')
I want to see 'some text' as output in console when file B executed. I think Something like (in any way that can be done):
def func(value):
main().do(value)
can solve problem.
doif you run the A-file. If you run the B-file,dowill not be defined. That's the meaning ofif __name__ == "__main__".ifstatement that checks the value of__name__is not an entry point to the script, like the function namedmainin C or Java. All Python programs start at the top and execute statements in order. Are you sure you even want such anifstatement?