| Absolute |
Standard approach; searches from sys.path roots. Preferred for clarity and PEP 8 compliance.
|
import os
os.path.join('a', 'b') |
| From Style |
Injects specific attributes directly into the local namespace. Reduces verbosity. |
from math import sqrt
foo = sqrt(16) |
| Alias |
Renames modules/functions to avoid naming conflicts or to shorten long names. |
import pandas as pd
df = pd.DataFrame() |
| Relative |
Uses . or .. for intra-package navigation. Only works within packages. |
from . import utils
utils.log("status") |
| Dynamic |
Loads modules at runtime via strings (could be from config files). Essential for plugin systems and lazy
loading.
|
import importlib
mod = importlib.import_module('sys')
|
| Wildcard |
Imports everything not starting with an underscore.
Highly discouraged; pollutes namespace.
|
from math import *
bar = sin(3.14) |