[ create a new paste ] login | about

Link: http://codepad.org/Y4xXyjJO    [ raw code | output | fork ]

Python, pasted on Feb 22:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import functools

def wrapmethod(f):
    @functools.wraps(f)
    def wrap(*args, **kwargs):
        print '>> %s' % (f.func_name)

        # Here I'll do pre-processing
        r = f(*args, **kwargs)
        # Here I'll do post-processing

        return r

    return wrap

@wrapmethod
def foo():
    pass

class Test(object):
    @wrapmethod
    def foo(self):
        pass

test = Test()
test.foo()
foo()


Output:
1
2
>> foo
>> foo


Create a new paste based on this one


Comments: