Python - Module Module Creation


To define a module, type some Python code into a text file, and save it with a ".py" extension.

Such file is automatically considered a Python module.

All the names assigned at the top level of the module become its attributes.

During import they are exported for clients to use.


Type the following def into a file called

Here, you create a module object with one attribute: the name printer, which happens to be a reference to a function object:

def printer(x):                   # Module attribute