wiki:python/Decorator

Python PEP 318


A brief Python decorator primer
Python Decorators
Decorator mit Argument aufrufen...
Python Decorators
Decorators and Functional Python


Examples

Decorator with parameter

def currency(sign):
    def _currency(func):
        def prefix(*args, **kwargs):
            return sign + str(func(*args, **kwargs))
        return prefix
    return _currency

@currency('EUR ')
def price(net_amount, tax):
    return net_amount * (1 + (tax * .01))
Last modified 5 years ago Last modified on Mar 18, 2014, 7:13:32 PM