Keywords and Control Flow

from — Import origins and generator delegation

A reserved keyword with distinct roles in imports, generator delegation and explicit exception chaining. In a from import, choose a source module and bind selected attributes or submodules; leading dots describe package-relative imports. A bound imported name is not a live alias of later module rebinding. With yield from, delegate to another iterable; with raise from, set the explicit exception cause (or suppress displayed context using None). These forms share spelling, not a single runtime operation.

Formal Syntax & Structure

python syntaxpython
from module import name [as alias]from . import siblingyield from iterableraise error from cause

Working Example

Example Snippetpython
from math import isqrt as root
def scores():    yield from [3, 5]
print(root(49))print(list(scores()))
Python Reference