Python Tutorials - Herong's Tutorial Examples - v2.14, by Herong Yang
"from module import member" Statement
This section provides a quick introduction of 'from module import member' statement, which imports a specific member of a given module.
What Is "from module import member" Statement? A "from module import member" statement is a variation of the "import" statement that imports a specific member of a given module. It uses these these syntax:
from module_name import member_name from module_name import member_name as variable_name
When a "from module_name import member_name" statement is executed, Python system will do the following:
The following code shows you how to import a specific member defined in the module file.
# import class "first" from "module_test.py" as a local variable "f" >>> from module_test import first as f Hi there! - from 'module_test' module Welcome on board! - from 'first' class >>> type(f) <class 'type'> >>> o = f() >>> o.rise() count = 1 - from 'rise()' method >>> o.rise() count = 2 - from 'rise()' method
Note that a "from module_name import member_name" statement actually loads the entire module file into memory cache. But it gives you no access to the module.
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