Python - Module Module Creation

Introduction

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.

Example

Type the following def into a file called module1.py.

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 
     print(x)