Count nb call of a function, without global var or decorator

M

Méta-MCI

Hi!

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?


@-salutations

Michel Claveau
 
M

Méta-MCI

Re!

I can do :

def ff():
this=ff
try:
this.count=this.count+1
except:
this.count=1
a=1
b=2
c=a+b

ff()
fa=ff
ff()
fa()

print ff.count


But that use, inside the function, the litteral name of the function; and I
want no use litteral name (inside)

@+

Michel Claveau
 
M

Méta-MCI

Re!

If the iterator is extern (to the function), it's like decorator, or global
var.
If it is internal, it's huge, compare to this.count=this.count+1 (or
this.count+=1)


@+

Michel Claveau
 
B

Bjoern Schliessmann

Méta-MCI said:
If the iterator is extern (to the function), it's like decorator,
or global var.

Please excuse me, I don't understand your point. I'm not even sure
if both of us speak of the same iterators.
If it is internal, it's huge, compare to this.count=this.count+1
(or this.count+=1)

In which way huge? If you want top notch performance you should use
a C extension anyway ...

Regards,


Björn
 
D

Duncan Booth

Méta-MCI said:
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:
def __init__(self):
self.count = 0
def __call__(self, notused):
self.count += 1
a, b = 1, 2
c = a+b
return c

0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top