from .Bar_implementation import *from .Baz_implementation import *__all__ = ['Bar', 'Baz']
如果您还没有准备好在顶级API中发布Baz,那么在您的顶级__init__.py中,您可以:
from .module_1 import * # also constrained by __all__'sfrom .module_2 import * # in the __init__.py's__all__ = ['foo', 'Bar'] # further constraining the names advertised
$ cat > main.pyfrom lib import export__all__ = [] # optional - we create a list if __all__ is not there.
@exportdef foo(): pass
@exportdef bar():'bar'
def main():print('main')
if __name__ == '__main__':main()
$ cat > run.pyfrom main import *foo()bar()main() # expected to error here, not exported
$ python run.pyTraceback (most recent call last):File "run.py", line 4, in <module>main() # expected to error here, not exportedNameError: name 'main' is not defined
>>> from cheese import *>>> swiss, cheddar(4.99, 3.99)>>> goudaTraceback (most recent call last):File "<stdin>", line 1, in <module>NameError: name 'gouda' is not defined