Let's say we have an app, app.py, that does a variety of things. Of course, along the way, there is bound to be "helper" functions that do things such as cleaning data, creating a visualization, doing currency conversion, etc etc. I've learned that storing these helper functions elsewhere is helpful in decluttering the main script, increasing readability. My question regards the most pythonic way to import these helper functions to the main script.
The way I've been doing it is the following:
app_dir
|
|
|----- helper_modules
| |_ __init__.py
| |_ module1.py
| |_ module2.py
| |_ module3.py
|
|----- app.py
And importing them the following way in app.py:
from helper_modules.module1 import _function(s)_
from helper_modules.module2 import _function(s)_
from helper_modules.module3 import _function(s)_
And everything works fine. However, I've seen source code that does it the following way (example here):
app_dir
|
|
|----- utils
| |_ module1.py
| |_ module2.py
| |_ module3.py
|
|----- app.py
And import the scripts the following way in app.py:
from utils import module1, module2, module3
Ultimately, my question is: What is the most pythonic way to import custom scripts into the main file? Do you want to turn the folder of helper functions into a module by including the __init__.py file or is just creating a utils folder fine? Also, instead of helper_modules in the first example, should it be renamed to utils (that is, is that a conventional naming rule)? I want to make sure my directory structure is as pythonic and readable as possible as others will be reading it.
from helper_modules import module3then in the main script utilizing the function withmodule3.function(...)@chepner?module1.foocomes from compared to a bare namefoobeing added to the global namespace.