I have a package myapp with the following structure:
/myapp
__init__.py
User.py
Inside the User.py:
from flask_login import UserMixin
class User(UserMixin):
def __init__(self, id):
#more
To import it I have to use:
from myapp.User import User
Is it possible to self-define the user.py file as a class the same way you can in Java? And then import it: from myapp import User?
I guess that the only way to do is define the User inside the __init__.py. Is it so?
Userin__init__.py:from User import Userand thenfrom myapp import Usershould work fine. But what's wrong with the current way?user.pyonly defines a single class, then perhaps it can be merged with another module.from .user import User(note the dot in.user) or use an absolute importfrom myapp.user import User. Using implicit relative import will break code when moving to different python versions and can even break code in other ways (e.g. problems with pickled data using theUserclass imported in the wrong way)...