The keys of globals() are the _names_. You're giving it the function
itself.
Ow, ok. I didn't caught it. I understand now.
> A decorator would be better.
Yes. I keep the solution with
foo=Wraper(foo)
Thanks a lot all !
Laurent
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, Sep 29, 2011 at 10:08 AM, Laurent Claessens wrote:
> Hello
>
>
> Is it possible to count the number of time a function is called ?
> Of course, if I've access to the source code, it's easy.
>
> I tried the following :
>
> def foo():
> print "foo !"
>
>
> class wraper(object):
> d
On 29/09/2011 18:08, Laurent Claessens wrote:
Hello
Is it possible to count the number of time a function is called ?
Of course, if I've access to the source code, it's easy.
I tried the following :
def foo():
print "foo !"
class wraper(object):
def __init__(self,fun):
globals()[fun]=self.r
On Fri, Sep 30, 2011 at 3:08 AM, Laurent Claessens wrote:
> class wraper(object):
> def __init__(self,fun):
> globals()[fun]=self.replacement
> def replacement(*args):
> print "I'm replaced"
>
> foo()
> X=wraper(foo)
> foo()
>
> I was hoping that globals()[foo] would be replace
On Fri, Sep 30, 2011 at 3:08 AM, Laurent Claessens wrote:
> def foo():
> print "foo !"
>
>
> class wraper(object):
> def __init__(self,fun):
> globals()[fun]=self.replacement
> def replacement(*args):
> print "I'm replaced"
>
> foo()
> X=wraper(foo)
> foo()
Are you able to
Hello
Is it possible to count the number of time a function is called ?
Of course, if I've access to the source code, it's easy.
I tried the following :
def foo():
print "foo !"
class wraper(object):
def __init__(self,fun):
globals()[fun]=self.replacement
def replac