15. Декораторы.

def multiply_result(func):
    def multiplier(*args, **kwargs):
        return -1 * func(*args, **kwargs)

    return multiplier

@multiply_result
def get_random_value():
    return 4

def get_one_more_random_value():
    return 4

print get_random_value()
print get_one_more_random_value()
-4
4

Некоторые встроенные декораторы

class SomeClass(object):
    @classmethod
    def print_name(cls):
        print cls.__name__

class ChildClass(SomeClass):
    pass

SomeClass.print_name()
ChildClass.print_name()
SomeClass
ChildClass
class SomeOtherClass(object):

    @staticmethod
    def print_hello():
        print "Hello!"

SomeOtherClass.print_hello()
Hello!