[python] Pocet instancí objektu

Jiri Vit jirivit na jirivit.com
Středa Leden 25 18:19:18 CET 2006


Presne tak, to je ono. Taky me to napadlo az cestou z prace,
takze jsi me predbehl :-)

Jirka

On Wed, 25 Jan 2006 17:48:53 +0100, Leos Pol <leos na radiante-corp.com>  
wrote:

> Omlouvam se vsem, ale nejak mi to rozhodilo indentaci
>
>>>> class MyClass:
> ...
> ... counter = 0
> ...
> ... def __init__(self):
> ... MyClass.counter += 1
> ...
> ... def __del__(self):
> ... MyClass.counter -= 1
> ...
>>>>
>>>> print MyClass.counter
> 0
>>>>
>>>> c = MyClass()
>>>> print MyClass.counter
> 1
>>>>
>>>> d = MyClass()
>>>> print MyClass.counter
> 2
>>>>
>>>> c = MyClass()
>>>> print MyClass.counter
> 2
>>>>
>>>> del c
>>>> print MyClass.counter
> 1
>>>>
>>>> del d
>>>> print MyClass.counter
> 0
>>>>
> Snad uz to je ted ok,
> Leos
>
> _______________________________________________
>
> Python  mailing  list
>
> Python na py.cz
>
> http://www.py.cz/mailman/listinfo/python



-- 
Zdravi

Jiri Vit



Další informace o konferenci Python