Python Forum

Full Version: self.object
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys, i need to ask.
https://github.com/nengkya/PyQt/blob/mas...ainForm.py
Line 21 and below. Why :
self.layout = QGridLayout()
and
layout = QGridLayout()
give the same result ?
One sets it to be a class attribute, the other doesn't. As self.layout is not used in any other functions or referenced anywhere else, and setLayout was already called using it, it doesn't make a difference.

If there is no need to use it elsewhere however it shouldn't be a class attribute.
(Jan-28-2018, 06:20 PM)Mekire Wrote: [ -> ]If there is no need to use it elsewhere however it shouldn't be a class attribute
Sometimes it is necessary to keep a reference to an object, even if it is not used elsewhere. I don't know if this is the case here, but in python an instance exists only when there is at least one reference to this instance.