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:
- make bound method
- make class method
- do nothing (leave is)
if gets regular function, (1), , @timings produces regular function.
does solve problem?
Comments
Post a Comment