Common mistakes

Report a typo

Below are some common mistakes a learner can make while defining or importing modules. What happens when you make each mistake?

1.

# module.py

import module

print("Hello!")

2.

# math.py

from math import pi

3.

# module_1

name = "John"
print("You shouldn't print this!")
# module_2

from module_1 import name

print("Hello,", name)
Match the items from left and right columns
1
2
3
Code of both modules will be executed because whenever the module is imported it is fully executed.
Name shadowing: the import from the original module is impossible because the import system will search names in the custom module.
The code will be executed twice since a module is imported from itself.
___

Create a free account to access the full topic