Imports
Importing variables/functions without executing the code
# file1
test = "hello"
def main():
pass
if __name__ == "__main__":
c = "hello"
main()
# file2
from file1 import test
>> Main will not run!Importing Functions that Contain Global Variables
# file: test.py
thing1 = 1
def hello():
print(thing1)
# file: test1.py
from test import hello
thing1 = 4
hello()
# Running python3 test1.py
>> 1Last updated