[BangPypers] folder initialization issues

Anand Chitipothu anandology at gmail.com
Thu Aug 29 03:37:18 CEST 2013

On Thu, Aug 29, 2013 at 6:55 AM, Adivandhya <adivandhya at yahoo.co.in> wrote:

> hi friends,
>         Im a basic python developer, and i could not understand fully the
> purpose of adding __init__.py  in every folder we want to import .Could
> someone please help me out understanding this.(context is based on
> importing modules in flask).

Lets say you a python file x.py.
You can import it just using "import x".

If you have y/x.py, you would import it using "import y.x" or "from y
import x". Here x is a submodule of y and y is also a module. But where is
the file for module y now? Since y is a folder, Python expects
y/__init__.py for module y. That is a convention that Python uses.

So to use a folder as a module you need add __init__.py to it. Got it?


More information about the BangPypers mailing list