Reputation: 686
I created a new module called logs which structure is :
logs
|_models
|_models.py
In this models.py I have a class :
import logging
class Log():
def __init__(self):
self.x=5
.
.
.
def warning(self,msg):
print(msg)
Now I want to call this warning function from other module called contacts which structure is also :
contacts
|_models
|_models.py
in this models.py I import my module logs like this :
from ... import logs
and i call warning function like this :
log = logs.models.models.Log()
log.warning("YAYYYYY")
This works fine. But I would like to have a smaller line instead of logs.models.models.Log() .Something like log=Log() . What change should i do in the code?
Info : Both modules are in addons folder.
Upvotes: 0
Views: 159
Reputation: 30957
Start with
from ...logs.models.models import Log
The official docs for this are at https://docs.python.org/3/reference/simple_stmts.html#grammar-token-import_stmt .
Upvotes: 1