Python: How to count the number of objects created?

前端 未结 5 1062
迷失自我
迷失自我 2020-12-20 22:46

I\'m new to Python. My question is, what is the best way to count the number of python objects for keeping track of number of objects exist at any given time? I thought of u

5条回答
  •  旧巷少年郎
    2020-12-20 23:46

    I would implement the following

    class baseMENUS: """A class used to display a Menu"""

    iMenuNumber = 0
    
    def __init__ (self, iSize):
        baseMENUS.iMenusNumber += 1
        self.iMenuSize = iSize
    
    def main():
       objAutoTester = baseMENUS(MENU_SIZE_1)
       ....
       ....
       ....
       objRunATest = baseMENUS(MENU_SIZE_2)
    

提交回复
热议问题