def setup_once(initfn):
def wrap(method):<EOL><INDENT>finit = initfn.__name__<EOL>fnname = method.__name__<EOL>@functools.wraps(method)<EOL>def wrapped(self, *args, **kwargs):<EOL><INDENT>@functools.wraps(method)<EOL>def aftersetup(*a, **kw):<EOL><INDENT>return method(self, *a, **kw)<EOL><DEDENT>setupfn = getattr(self, finit)<EOL>setupfn(*args, **kwargs)<EOL>res = method(self, *args, **kwargs)<EOL>setattr(self, fnname, aftersetup)<EOL>return res<EOL><DEDENT>return wrapped<EOL><DEDENT>return wrap<EOL>
call class instance method for initial setup ::

    class B(object):

        def init(self, a):
            print 'init call:', a

        @setup_once(init)
        def mycall(self, a):
            print 'real call:', a

    b = B()
    b.mycall(222)
    b.mycall(333)

:param function initfn:
:return: decorated method