pytho interpreter parameters of those things _inspect.getcallargs

'' ' 
The Created ON Jul 26, 2019 

@author: Tomcat 
' '' 

Import the Inspect 
DEF chack_admin (FUNC): 
    DEF wrapper (* args, ** kwargs): 
        '' ' 
        inspect.getcallargs returns a dictionary, the dictionary function preserved All parameters 
        inspect.getcallargs (func [, * args] [, ** kwds]): the kwds args parameter and the parameter name to bind to the func; bound to the method, the first parameter bind (usually self) to the corresponding instance; return dictionary, the corresponding parameter names and their values; ''
        ' 
        fuc_args = inspect.getcallargs (FUNC, args *, ** kwargs) 
        Print ( "Arg {}, {} keord, fuc_args {}" .format (args, kwargs, fuc_args)) 
        IF fuc_args.get ( "username") == "ADMIN": 
            Re = FUNC (* args, ** kwargs) 
        the else: 
            The raise Exception ( 'Not eligible to add or delete elements') 
        return Re
    warpper return 
    m.push(username="admin",item=902)
MyClass class (Object): 
    DEF the __init __ (Self): 
        self.item = [90.89] 
    '' ' 
     if the username = admin, add an element not qualified! 
    ' '' 
    @chack_admin 
    DEF Push (Self, username, Item): 
        Self. item.append (Item) 
    '' ' 
    ! If the username = admin, are not eligible to delete an element 
    ' '' 
    @chack_admin    
    DEF POP (Self, username): 
        IF self.item: 
            return self.item.pop () 
        the else: 
            The raise Exception ( 'item no elements') 
IF the __name__ == '__main__': 
    m = MyClass () 
    m.push ( 'ADMIN', 10) 
    m.pop (username = 'ADMIN')
    print(m.item)

 

arg(<__main__.MyClass object at 0x10c5b5240>, 'admin', 10),keord{},fuc_args{'self': <__main__.MyClass object at 0x10c5b5240>, 'username': 'admin', 'item': 10}

arg(<__main__.MyClass object at 0x10c5b5240>,),keord{'username': 'admin', 'item': 902},fuc_args{'self': <__main__.MyClass object at 0x10c5b5240>, 'username': 'admin', 'item': 902}

arg(<__main__.MyClass object at 0x10c5b5240>,),keord{'username': 'admin'},fuc_args{'self': <__main__.MyClass object at 0x10c5b5240>, 'username': 'admin'}

[90.89, 10]

Guess you like

Origin www.cnblogs.com/tallme/p/11247899.html