Python Forum
Passing Variables up and down through classes
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing Variables up and down through classes
#2
One way is to use inheritance.

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:
Reply


Messages In This Thread
RE: Passing Variables up and down through classes - by metulburr - May-09-2017, 12:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Organizing several similar classes with overlapping variables 6hearts 7 1,485 May-07-2023, 02:00 PM
Last Post: 6hearts
  Passing Variables between files. victorTJ 3 2,312 Oct-17-2020, 01:45 AM
Last Post: snippsat
  Python 2.7 passing variables from functions zetto33 1 1,812 Mar-19-2020, 07:27 PM
Last Post: Larz60+
  help with threading module and passing global variables ricardons 1 7,926 Feb-21-2019, 12:48 PM
Last Post: stullis
  I can't use file __init__ to store shared variables and classes in the package AlekseyPython 2 3,391 Feb-04-2019, 06:26 AM
Last Post: AlekseyPython
  How can classes access each other Functions and Variables at the same time PythonOK 4 3,108 Dec-09-2018, 03:46 AM
Last Post: ichabod801
  Class Modules, and Passing Variables: Seeking Advice Robo_Pi 21 10,433 Mar-02-2018, 05:22 PM
Last Post: snippsat
  Using classes? Can I just use classes to structure code? muteboy 5 5,149 Nov-01-2017, 04:20 PM
Last Post: metulburr
  global variables, classes, imports Skaperen 16 10,811 Mar-02-2017, 11:05 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020