How to apply a Python timings decorator to a method within a class -


i trying apply timing decorator described here method within class instead of standalone method. how should done?

i getting error:

 typeerror: unbound method wrapper() must called someclass instance first argument (got float instance instead) 

edit

thanks comment, think know problem is. doesn't work:

class a:      @timings     @classmethod     def a(cls, x):        print(x)  a.a(2) 

for reason said. typeerror: unbound method wrapper() must called instance first argument (got int instance instead)

but does:

class a:      @classmethod     @timings     def a(cls, x):         print(x)  a.a(2) 

so order matters. think what's going on here it's fooling way python handles bound methods: when python looks @ member a, has make decision:

  1. make bound method
  2. make class method
  3. do nothing (leave is)

if gets regular function, (1), , @timings produces regular function.

does solve problem?


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -