wrapper - python decorate function call -


i learned decorators , wondered if it's possible use them not in function definition in function call, kind of general wrapper.

the reason is, want call functions module through user-defined interface repeatable things function , don't want implement wrapper every single function.

in principle have like

def a(num):     return num  @double a(2) 

returning 4 without need of having access implementation of a. or in case global wrapper like

def mutiply(factor,function,*args,**kwargs):     return factor*function(*args,*kwargs) 

be better choice?

there detailed section on decorators in marty alchin's book pro python apress.

while new style @decorator syntax available used @ function definition, can use older syntax, same thing way:

from module import myfunc  myfunc = double_decorator(myfunc)  x = myfunc(2) # returns 4 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -