Okay yet one more helpful put up. This put up is basically necessary and helpful for anybody simply beginning out with python. So what’s the
__init__.py file ?
__init__.py are used to mark directories on disk as Python bundle directories. You probably have the next information:
mydir is in your path, you may import the code in
from spam import module
When you take away the
__init__.py file, Python will not search for submodules inside that listing, so makes an attempt to import the module will fail.
__init__.py file is normally empty, however can be utilized to export chosen parts of the bundle beneath extra handy title, maintain comfort capabilities, and so forth. Given the instance above, the contents of the init module might be accessed as
And eventually here’s what the official documentation has to say about this file:
__init__.pyinformation are required to make Python deal with the directories as containing packages; that is performed to forestall directories with a typical title, comparable to string, from unintentionally hiding legitimate modules that happen afterward the module search path. Within the easiest case,
__init__.pycan simply be an empty file, however it could actually additionally execute initialization code for the bundle or set the
__all__variable, described later.