"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

 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