I was curious what happens when we import a module that in turn imports another module. So I create two modules: module1 and module2.
module1:
import random
print(random.randint(0,10))
print("module1 work")
module2:
import module1
print("module2 work")
When I run module2 it give me this output:
1
module1 work
module2 work
So, I decided that I did indeed import random, when I imported module1. But when I type in the Shell print(random.randint(0,10))it throws a NameError: name 'random' is not defined. So random wasn't imported from module1. But in this case why did module2 print 1, and didn't throw the same error as the Shell?
moduleobject is bound to a name in the global namespace. Trymodule1.random.randint(0,10).