The if __name__ == '__main__'
is mainly used to make a single python script executable. For instance, you define a function that does something, you use it by importing it and running it, but you also want that function to be executed when you run your python script with python module1.py
.
For the question you asked, the best I could come up with is that you wanted a function defined in "module1.py" to run when you invoke "module2.py". That would be something like this:
### module1.py:
def main():
# does something
...
if __name__ == '__main__':
main()
### module2.py:
from module1 import main as main_from_module_one
if __name__ == '__main__':
main_from_module_one() # calling function main defined in module1