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

 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

 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

 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