본문 바로가기
Python

command pattern

by SpeeDr00t 2016. 11. 22.
반응형

command pattern

1.소스

  
def demo(a,b,c):
    print 'a:',a
    print 'b:',b
    print 'c:',c

class Command:
    def __init__(self, cmd, *args):
        self._cmd=cmd
        self._args=args

    def __call__(self, *args):
       return apply(self._cmd, self._args+args)


if __name__ == "__main__":

    cmd=Command(dir,__builtins__)
    print cmd()

    cmd=Command(demo,1,2,3)
    cmd()



결과


반응형

'Python' 카테고리의 다른 글

jamo 사용하기 ][ h2j , j2h , j2hcj 사용하기  (0) 2019.03.06
C like structures in Python  (0) 2016.11.22
whitehat cft 문제  (0) 2016.10.10
powershell(ubuntu version)에서 python 호출하기  (0) 2016.08.22
tuple  (0) 2016.07.21