to find later files module namespace initialization in the package import modelthe directory paths in your script become real nested object paths after an import for instancein the preceding exampleafter the import the expression dir dir works and returns module object whose namespace contains all the names assigned by dir ' __init__ py initialization file such files provide namespace for module objects created for directorieswhich would otherwise have no real associated module file from statement behavior as an advanced featureyou can use __all__ lists in __init__ py files to define what is exported when directory is imported with the from statement form in an __init__ py filethe __all__ list is taken to be the list of submodule names that should be automatically imported when from is used on the package (directoryname if __all__ is not setthe from statement does not automatically load submodules nested in the directoryinsteadit loads just names defined by assignments in the directory' __init__ py fileincluding any submodules explicitly imported by code in this file for instancethe statement from submodule import in directory' __init__ py makes the name available in that directory' namespace (we'll see additional roles for __all__ in it serves to declare from exports of simple files as well you can also simply leave these files emptyif their roles are beyond your needs (and franklythey are often empty in practicethey must existthoughfor your directory imports to work at all don' confuse package __init__ py files with the class __init__ constructor methods we'll meet in the next part of the book the former are files of code run when imports first step through package directory in program runwhile the latter are called when an instance is created both have initialization rolesbut they are otherwise very different package import example let' actually code the example we've been talking about to show how initialization files and paths come into play the following three files are coded in directory dir and its subdirectory dir --comments give the pathnames of these filesdir \__init__ py print('dir init' dir \dir \__init__ py print('dir init' package import example