"Méta-MCI" <[EMAIL PROTECTED]> wrote:

> Example, with meta-data (attributs of function) :
> 
> def ff(this):
>     try:
>         this.count=this.count+1
>     except:
>         this.count=1
>     a=1
>     b=2
>     c=a+b
> 
> ff(ff)
> fa=ff
> ff(ff)
> fa(fa)
> print ff.count
> 
> 
> 
> How to improve that?

If I've managed to guess what you are asking, you want to use a class:

>>> class Ff:
        def __init__(self):
                self.count = 0
        def __call__(self, notused):
                self.count += 1
                a, b = 1, 2
                c = a+b
                return c

        
>>> ff = Ff()
>>> fa = Ff()
>>> ff(ff)
3
>>> ff.count
1
>>> fa.count
0
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to