Section thirty decorator with parameters

def set_lenvl(level_num):
    def set_func(func):
        def call_func(*args, **kwargs):
            if level_num == 1:
                print('-----------权限%d-----------' % level_num)
            else:
                print('-------权限%d--------' % level_num)
            return func(*args, **kwargs)
        return call_func
    return set_func

@set_lenvl(1)  #The argument passed as a function set_level, then the return value of a function as a decoration, a decoration objective function 
DEF tsl ():
     Print ( ' ------ --------- tsl ' ) 

@set_lenvl ( 2 )
 DEF TS2 ():
     Print ( ' --------- ------- TS2 ' ) 

tsl () 
TS2 ()

 

Guess you like

Origin www.cnblogs.com/kogmaw/p/12602574.html