Python Module

A python module is a place where you can communicate with other files .

For example consider a folder structure like this:

├── src
│   └── main.py
└── tests
    └── main_test.py

In your main_test.py you want to call the main.py. As a result, you might think of doing something like this:

import src.main as app

app.someFunction()

However, for this to work, both src and tests have to be within a module.

To initiate them as module, you can just create a file call __init__.py in those folder:

├── src
│   ├── __init__.py
│   └── main.py
└── tests
    ├── __init__.py
    └── main_test.py

And the code above will work. They now can refer to each other

Relative path

If the 2 files are in the same module, we can use relative path, for example

├── src
│   ├── __init__.py
│   ├── fileA.py
│   └── fileB.py

In this case, fileA.py and fileB.py are in the same module. The two file can refer to each other like this:

form .fileA import ...

# or


form .fileB import ...