In this lesson, you’ll learn about reloading a module. For efficiency, a module is only loaded once per interpreter session. That’s fine for function and class definitions, which typically make up the bulk of a module’s contents.
But a module can contain executable statements as well, usually for initialization. Be aware that these statements will only be executed the first time a module is imported.
Take a look at mod.py
:
s = "Computers are useless. They can only give you answers."
a = [100, 200, 300]
def printy(arg):
print(f'arg = {arg}')
class Classy:
pass
print(f'a = {a}')
Here’s what you get:
J on May 16, 2020
Ok, and the usefulness is how? I am not seeing the use case for this and why it is useful to know about it?