1#Add this code to run a support module on its own.
2#Great for running quick tests.
3
4if __name__ == "__main__":
5 function_that_starts_the_module_to_run_on_its_own()
6 #or
7 test_function_included_in_module()
1print("before import")
2def functionA():
3 print("Function A")
4def functionB():
5 print(("Function B"))
6print("before __name__")
7if __name__ == '__main__':
8 functionA()
9 functionB()
10print("after __name__")
11#===Output===
12#before import
13#before __name__ guard
14#Function A
15#Function B
16#after __name__ guard
1# Suppose this is foo.py.
2
3print("before import")
4import math
5
6print("before functionA")
7def functionA():
8 print("Function A")
9
10print("before functionB")
11def functionB():
12 print("Function B {}".format(math.sqrt(100)))
13
14print("before __name__ guard")
15if __name__ == '__main__':
16 functionA()
17 functionB()
18print("after __name__ guard")