Reputation: 2884
I am making a python package where I currently have a structure as below:
application/utils.py
class settings():
function foo():
bla bla bla
class debug():
function bar():
bla bla bla
Then in other modules the import of the settings and debug classes can be done as below:
import application.utils.settings
import application.utils.debug
But now, the classes are getting pretty big and I would like to put them in separates files.
application/utils/settings.py
class settings():
function foo():
bla bla bla
application/utils/debug.py
class debug():
function bar():
bla bla bla
In that case, importing the debug and settings classes would be as below:
import application.utils.settings.settings
import application.utils.debug.debug
That I feel quite unnatural. Is it the right way to do that or am I missing something?
Upvotes: 2
Views: 85
Reputation: 8231
You can write in application/utils/__init__.py
:
from application.utils.settings import Settings
from application.utils.debug import Debug
Then you will access Settings
and Debug
classes shorter
from application.utils import Settings
from application.utils import Debug
Don't name your classes and modules the same. Read PEP8 about naming convention
Upvotes: 5
Reputation: 55207
Import your classes in your utils/__init__.py
file and import them as you used to.
Upvotes: 0