Python Tutorials - Herong's Tutorial Examples - v2.14, by Herong Yang
What Is __all__ List
This section provides a quick introduction on __all__ list, which is a special module attribute defined in the module file to override which members can be implicitly imported by the 'from module import *' statement.
What Is __all__ List? A __all__ list is a special module attribute defined in the module file to override which members can be implicitly imported by the "from module import *" statement.
Here is what I did to test the __all__ list.
1. Copy module_test.py to module_test_2.py and the __all__ list:
# module_test_2.py #- Copyright 2011 (c) HerongYang.com. All Rights Reserved. # print("Hi there! - from 'module_test' module") version = "1.00 - from 'version' attribute" def help(): print("How can I help you? - from 'help()' function") class first: print("Welcome on board! - from 'first' class") count = 0 def rise(self): first.count += 1 print(f"count = {first.count} - from 'rise()' method") __all__ = ['help', 'first']
2. Run "from module_test_2 import *".
herong$ python >>> from module_test_2 import * Hi there! - from 'module_test' module Welcome on board! - from 'first' class >>> help() How can I help you? - from 'help()' function >>> o = first() >>> o.rise() count = 1 - from 'rise()' method >>> version NameError: name 'version' is not defined
The output matches well with my expectation!
Table of Contents
Variables, Operations and Expressions
Function Statement and Function Call
Iterators, Generators and List Comprehensions
"import module" - Two-Step Process
sys.modules - Listing Loaded Modules
importlib.reload(module) - Reloading Module
"from module import member" Statement
"from module import *" Statement
__pycache__/module.version.pyc Files
Packages and Package Directories
"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