Im working on the rental class now .
The rental class is needed for the rental object which has attributes from the other classes
I am trying to initialize the other attributes by using super.init
Is this correct, please advise.Using python 3.5
Im working on the rental class now .
The rental class is needed for the rental object which has attributes from the other classes
I am trying to initialize the other attributes by using super.init
Is this correct, please advise.Using python 3.5
No, You don't need to initialise always. A class is initialized once by super.init. If you need to access the attributes from one class to another class do one thing make them available on the main thread i.e by using (self. "attribute"). As you know in Python every class works on the separate thread. So basically you need to make that attribute available on the main thread and then call that.
For eg here's a code snippet for multithreading I wrote.
class workerThread(QThread):
signal = pyqtSignal(str)
def __init__(self):
super().__init__()
self.abort = False
@pyqtSlot()
def run(self):
#print("yeah yeah ")
time.sleep(0.1)
app.processEvents()
self.signal.emit('Done')
def __del__(self):
#print("okay okay")
self.abort = True
self.wait()
class General(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def saveClicked(self):
try:
tex=[]
for edit in self.lineedits:
tex.append(str(edit.text()))
if tex[0] and tex[1] and tex[2]:
if ('@gmail.com' in str(tex[1])) or ('@yahoo.com' in str(tex[1])) or ('@' in str(tex[1])):
contact=str(tex[2])
if self.validContact(contact):
self.workerthread = workerThread()
self.workerthread.signal.connect(self.savesuccess)
self.workerthread.start()
else:
self.workerthread = workerThread()
self.workerthread.signal.connect(self.errorcontactmsg)
self.workerthread.start()
else:
self.workerthread = workerThread()
self.workerthread.signal.connect(self.erroremailmsg)
self.workerthread.start()
else:
self.workerthread = workerThread()
self.workerthread.signal.connect(self.errornormmsg)
self.workerthread.start()
except:
self.workerthread = workerThread()
self.workerthread.signal.connect(self.crashingmsg)
self.workerthread.start()
Refer this Link for full code to have an Idea - Link
or even if you just want to initialize then,
class Tetrominoe(object):
NoShape = 0
class Shape(object):
def __init__(self):
self.coords = [[0,0] for i in range(4)]
self.pieceShape = Tetrominoe.NoShape
self.setShape(Tetrominoe.NoShape)
But using self to call def attributes of one class in another is a better option attach that attribute on main thread by "self. " and access it in any class then.
Quite New with Python but hope this helps.
Go through this - How would I access variables from one class to another? it will be more helpfull.