Skip to main content
GameDev.net gamedev.net
🔒 Locked

Static Class Member

Started by PhlashStudios May 28, 2006 at 9:45 AM 0 replies 600+ views
Original Post
PhlashStudios
PhlashStudios
Hey everyone I just had a quick question: How would I create a static class member in Python. So for example if I had a class called Cat, and everytime I init a cat it adds 1 cat to the count of every instance of the cat class.
<a href="http://eyeredux.com/campaigns/1/redirect">Hello!</a>
Kylotan
Kylotan
Just add them to the class definition, rather than the __init__ method which is for the instance.
>>> class Cat(object):	count=0	def __init__(self):		Cat.count += 1		>>> x = Cat()>>> y = Cat()>>> print Cat.count2>>> 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.