Modules Flashcards
What is a python module?
A module is a collection of python declarations intended to be used as a tool. The basic syntax is.
from module_name import object_name
> from datetime import datetime
You can also select the whole module for use:
import random
> random.choice(my_list)
Explain module namespacing
A namespace isolates the function, classes and variables defined in the module from the code in the file doing the callng.
The name of the module is the name given to the namespace by default. This can be changed however using aliasing.
import module_name as name_you_pick_for_the_module
if __name__ == ‘__main__’ ?
‘__main__’ refers to the current module being executed. so the calls will not be executed unless it was called locally.