What is __init__.py for?

Explanation

If you have the following files. So the files name with __init__.py are used to mark directories on disk as Python package directories. 

mydir/spam/__init__.py
mydir/spam/module.py

and mydir is on your path, you can import the code in module.py as

import spam.module

or you can also write as :

from spam import module

Attempts will get fail if you try to import the module. Python will no longer look for submodules inside that directory If you remove the __init__.py file.

Generally, __init__.py file is usually empty. But under the more convenient name, you can use export selected portions of the package 

 

Also read, How to concatenate string variables in Bash

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *