code style 1:
from ..service.user_service import UserService
class UserView:
user_service = UserService()
user_service.get_all_users()
# rest of code
code style 2:
from ..service.user_service import UserService as userService
class UserView:
userService.get_all_users()
# rest of code
service.user_service.py
from .models.user import User # please
class UserService:
def get_all_users(self):
return User.objects.all()
both code works fine but which is the proper way? And also I want to know if this things may cause of the circular import error
?. I have went through this question Circular (or cyclic) imports in Python.
And what is the working mechanism of style 2
code?