Cached Import, Correct Main Guard
Two files in the same directory:
# mod.py
print("loading mod")
if __name__ == "__main__":
print("running mod directly")
else:
print("mod imported")
def greet():
return "hi from mod"
# main.py
import mod
import mod
print("main is", __name__)
print(mod.greet())
You run python3 main.py. What prints, in order?
Sign in to answer questions and track your progress
Sign In