Python Tutorials - Herong's Tutorial Examples
∟Modules and Module Files
This chapter provides introductions and tutorial examples about on modules and module files. Topics include introduction of 'module' objects and module files; importing module files to create modules; reloading modules; accessing module members; importing module members only.
What Is Module
"import module" - Two-Step Process
sys.modules - Listing Loaded Modules
importlib.reload(module) - Reloading Module
What Are Module Members
"from module import member" Statement
"from module import *" Statement
What Is __all__ List
__pycache__/module.version.pyc Files
What Is the __main__ Module
Takeaways:
- A module is an object of the "module" data type
that can store attributes, functions, class classes.
- There is no Python statement you can use to create "module" object.
- "module" objects are created from module files by
running "import" statements.
- A module file, module_name.py, contains Python code
to define module members: attributes (variables), functions, and classes.
- "import module_name" statement loads a module file into memory
and binds it module_name as a local variable.
- "import module_name as variable_name" statement loads a module file into memory
and binds it variable_name as a local variable.
- "from module_name import member_name" statement loads a module file into memory
and binds the given member to member_name as a local variable.
- "from module_name import *" statement loads a module file into memory
and binds each member to member_name as a local variable.
- The __main__ module is created by the Python system as the first module
to start executing user specified Python code.
Table of Contents
About This Book
Running Python Code Online
Python on macOS Computers
Python on Linux Computers
Built-in Data Types
Variables, Operations and Expressions
Statements - Execution Units
Function Statement and Function Call
Iterators, Generators and List Comprehensions
Classes and Instances
►Modules and Module Files
Packages and Package Directories
"sys" and "os" Modules
"pathlib" - Object-Oriented Filesystem Paths
"pip" - Package Installer for Python
SciPy.org - Python Libraries for Science
pandas - Data Analysis and Manipulation
Anaconda - Python Environment Manager
Jupyter Notebook and JupyterLab
References
Full Version in PDF/EPUB