"from module import *" Statement

This section provides a quick introduction of 'from module import *' statement, which imports all members of a given module.

What Is "from module import *" Statement? A "from module import *" statement is a variation of the "import" statement that imports all members of a given module.

When a "from module_name import *" statement is executed, Python system will do the following:

The following code shows you how to import all members defined in the module file.

>>> from module_test import *
Hi there! - from 'module_test' module
Welcome on board! - from 'first' class

>>> version
"1.00 - from 'version' attribute"

>>> help()
How can I help you? - from 'help()' function

>>> o = first()
>>> o.rise()
count = 1 - from 'rise()' method

Note that importing all members with the wildcard character has a potential risk of mess up existing variables, if their names are also used by module members. For example, what will be the value in "version" after running the code below?

>>> version = 3.9
>>> from module_test import *

You can reduce the this risk by using the __all__ list to control which members to be imported by the "from module import *" statement. See next tutorial.

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