En Thu, 30 Jul 2009 17:09:36 -0300, NighterNet <darkne...@gmail.com>
escribió:
On Jul 30, 12:14 pm, r <rt8...@gmail.com> wrote:
On Jul 30, 1:13 pm, NighterNet <darkne...@gmail.com> wrote:

> Need some help on doing some bit simple id count. It like every time
> it create a class orthreadthere is id++. Python 3.1

use a class atrribute

class Person():
  count = 0
  def __init__(self, name, info):
      self.name = name
      self.info = info
      Person.count+=1
      self.count = Person.count

Since you menctioned "thread" in the subject, note that the above isn't
thread-safe. You'll need a lock around the last two statements.

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to