Python Tutorials - Herong's Tutorial Examples - v2.14, by Herong Yang
"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
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