May-09-2017, 12:43 AM
One way is to use inheritance.
An example of how sub classes can alter the class variable "count"
so in your case
An example of how sub classes can alter the class variable "count"
class Employee: count = 0 def __init__(self): Employee.count += 1 class FullTime(Employee): pass class PartTime(Employee): def add_to(self, num): Employee.count += num print(Employee.count) obj1 = FullTime() obj2 = FullTime() obj3 = PartTime() print(Employee.count) obj3.add_to(3) print(Employee.count)
Output:0
3
6
All classes the super class Employee and the two sub classes FullTime and PartTime share count value. Whereas if you created an instance variable via self.var it would be per object.so in your case
class Configuration: pass class guiMainWindow(Configuration): pass class guiConfigWindow(guiMainWindow): pass
Recommended Tutorials: