Re: Counting the number of call of a function

2011-09-30 Thread Laurent Claessens
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

Re: Counting the number of call of a function

2011-09-29 Thread Chris Rebert
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

Re: Counting the number of call of a function

2011-09-29 Thread MRAB
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

Re: Counting the number of call of a function

2011-09-29 Thread Chris Angelico
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

Re: Counting the number of call of a function

2011-09-29 Thread Chris Angelico
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

Counting the number of call of a function

2011-09-29 Thread Laurent Claessens
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