class or thread id count
r
rt8396 at gmail.com
Thu Jul 30 15:14:12 EDT 2009
On Jul 30, 1:13 pm, NighterNet <darkne... at gmail.com> wrote:
> Need some help on doing some bit simple id count. It like every time
> it create a class or thread there is id++. Python 3.1
>
> example:
> class ClientThread (threading.Thread):
> def __init__(self,clientSocket):
> threading.Thread.__init__(self)
> self.id += 1;
>
> Not sure it how it works.
use a class atrribute
>>> class Person():
count = 0
def __init__(self, name, info):
self.name = name
self.info = info
Person.count+=1
>>> p1 = Person('alex23', 'very annoying')
>>> p2 = Person('Guido', 'very intelligent')
>>> p2.count
2
>>> p1.count
2
>>> Person.count
2
More information about the Python-list
mailing list