ImportError: cannot import name 'Users' from 'user'
You need to import only module/file you didn't need to import class. Where ever you want to use loginuser
class use it using app.loginUser()
and user.Users()
for Users
class. Below code works fine for me:
import appclass Users: def __init__(self,window): return app.loginUser()
import userclass loginUser: def __init__(self, window, master=None): return user.Users()
Your question is very unclear, you say "it returns me this error" but then do not provide the error you are getting. From what I can gather you should be getting the error : ImportError: cannot import name 'loginUser' from 'app' (C:\User\ProjectName\app.py)
This error is occurring because you are trying to import Users
from user.py
into app.py
, and also trying to import loginUser
from app.py
into users.py
. This is a import loop and causes the error.
In short,
user.py
cannot rely upon code fromapp.py
ifapp.py
also relies uponuser.py
itself.
One way to fix this error, is to import loginUser into the specific functions that it is needed within User (Or Vice Versa, depending on what your two classes need to do).
e.g. - If a Users object needs to create a new loginUser in a function called createUser()
, the two files would look like the following
# app.pyfrom user import Usersclass loginUser: #Metodo de inicio ao sistema de login def __init__(self, window, master=None): # Criando o sistema de login self.wind = window self.wind.title("System F2T")
# user.pyclass Users: def __init__(self,window): # Criando o sistema self.wind = window self.wind.title("System F2T") def createUser(self): from app import loginUser newUser = loginUser(self.wind) return newUser