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 5 1743
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éta-MCI wrote:
Example, with meta-data (attributs of function) :
Apart from asking what counting "nb call" of a function means, I
wonder why you didn't use an iterator?
@-salutations
@-less Regards,
Björn
--
BOFH excuse #65:
system needs to be rebooted
Re!
>>why you didn't use an iterator?
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
Méta-MCI wrote:
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
--
BOFH excuse #339:
manager in the cable duct
"Méta-MCI" <en**************@XmclaveauX.comwrote:
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ron_Adam |
last post by:
I'm trying to figure out how to test function arguments by adding a
decorator.
@decorate
def func( x):
# do something
return x
This allows me to wrap and replace the arguments with my own,...
|
by: Randell D. |
last post by:
Folks,
I'm sure this can be done legally, and not thru tricks of the trade - I
hope someone can help.
I'm writing a 'tool' (a function) which can be used generically in any
of my projects. ...
|
by: Lasse Vågsæther Karlsen |
last post by:
After working through a fair number of the challenges at
www.mathschallenge.net, I noticed that some long-running functions can
be helped *a lot* by caching their function results and retrieving...
|
by: oripel |
last post by:
Hi,
I'm trying to attach some attributes to functions and methods, similar
to Java annotations and .NET attributes.
I also want to use a convenient decorator for it, something along the
lines...
|
by: glomde |
last post by:
Hi,
I tried to write a decorator for that should be for methods but for
some reasons
it doens seem to work when you try to do it on the __getattr__ method
in a class.
Could anybody give some...
|
by: Miguel Perez |
last post by:
Please critique this tail call optimizing decorator I've written. I've
tried to fix the pitfalls of other proposed decorators, and the result
is this one that supports mutual recursion, does not...
|
by: Paddy |
last post by:
Hi,
# If I have a function definition
def f1(arg):
global capturecall
if capturecall:
...
do_normal_stuff(arg)
# and its later use:
def f2():
|
by: Rahul |
last post by:
Hi Everyone,
I have the following code and i'm able to invoke the destructor
explicitly but not the constructor. and i get a compile time error
when i invoke the constructor, why is this so?
...
|
by: mh |
last post by:
I am instantiating a class A (which I am importing from somebody
else, so I can't modify it) into my class X.
Is there a way I can intercept or wrape calls to methods in A?
I.e., in the code...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| | |