testdecorators.py

来自「Python Development Environment (Python I」· Python 代码 · 共 21 行

PY
21
字号
class CoolApproach(object):
    # this tests also a tuple "special case"
    def foodeco(constant, arg1, arg2="foo", arg3="usual", *arg4, **arg5):
        print arg1, arg2, arg3, arg4
    
    @foodeco(('arg_3', ), 2)
    def __init__(self, arg_1, (arg_2, arg_3), arg_4, arg_5):
        # .. at this point all parameters except for 'arg_3' have been
        # copied to object attributes
        # .. now do whatever initialisation is required ..
        print ">> In initialiser, self.arg_1 = '%s'" % self.arg_1
    

class FooApproach(CoolApproach):
    # this tests also a tuple "special case"
    @foodeco(5, ('arg_3', ), arg_2="test", arg_1="bla", *arg_4, **arg_5)
    def __init__(self, arg_1, (arg_2, arg_3), *arg_4, **arg_5):
        # .. at this point all parameters except for 'arg_3' have been
        # copied to object attributes
        # .. now do whatever initialisation is required ..
        print ">> In initialiser, self.arg_1 = '%s'" % self.arg_1

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?