人言落日是天涯,望极天涯不见家 a écrit :
> I define the class like this:
> class AAA:
>     counter = 0
>     def __init__(self):
>         pass
>     def counter_increase():
>         AAA.counter += 1
>         print "couter now :", AAA.counter

You probably want something like this:

class AAA(object):
     _counter = 0

     @classmethod
     def increase_counter(cls):
         cls._counter += 1
         print "%s._counter is now %d" % (cls.__name__, cls._counter)

> But how could I call the function "counter_incrrease" ?

With the above correction, you can call it eiter on the class or on an 
instance:

AAA.increase_counter()
aaa = AAA()
aaa.increase_counter()

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

Reply via email to