Python: How to count the number of objects created?

前端 未结 5 1064
迷失自我
迷失自我 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:27

    Use self.__class__.iMenuNumber or baseMENUS.iMenuNumber instead of self.iMenuNumber to set the var on the class instead of the instance.

    Additionally, Hungarian Notation is not pythonic (actually, it sucks in all languages) - you might want to stop using it. See http://www.python.org/dev/peps/pep-0008/ for some code style suggestions.

提交回复
热议问题