- __all__
- import
- from
Export import
- from mod import a,b,_c - import 'a', 'b', and '_c' from 'mod'
- from mod import * - import every name listed in __all__ of 'mod' if __all__ is available.
- from mod import * - import every name that does NOT start with _ (if __all__ is not available)
- import mod - import 'mod' and make every name in 'mod' accessible as 'mod.a', and 'mod._c'
examples/modules/my_module.py
def a(): return "in a" b = "value of b" def _c(): return "in _c" def d(): return "in d"
examples/modules/x.py
from my_module import a,b,_c print(a()) # in a print(b) # value of b print(_c()) # in _c print(d()) # Traceback (most recent call last): # File ".../examples/modules/x.py", line 7, in <module> # print(d()) # NameError: name 'd' is not defined
examples/modules/y.py
from my_module import * print(a()) # in a print(b) # value of b print(d()) # in d print(_c()) # Traceback (most recent call last): # File ".../examples/modules/y.py", line 9, in <module> # print(_c()) # in _c # NameError: name '_c' is not defined