Modules Flashcards

1
Q

What is a python module?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain module namespacing

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

if __name__ == ‘__main__’ ?

A

‘__main__’ refers to the current module being executed. so the calls will not be executed unless it was called locally.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly