How does the decorated function of python get the variable or return value of its decorator?

from functools import wraps

def test(func):
    @wraps(func)
    def inner_func():
        inner_obj = "inner_obj"
        print(inner_obj)
        return func()
    return inner_func


@test
def test_func():
    return False

a = test_func ()
print (a)

I want to get the inner_obj variable of the decorator in test_func. Excuse me

Dec.05,2021

of course.

you can add a parameter to test_func. Pass parameters when calling test_func in inner_func

from functools import wraps

def test(func):
    @wraps(func)
    def inner_func():
        inner_obj = 'inner_obj'
        print(inner_obj)
        return func(inner_obj)  -sharp
    return inner_func


@test
def test_func(obj):
    print(obj)      -sharp
    return False

a = test_func()
print(a)

is passed in as a parameter.

  Python decorator: identification criteria for getting started with python  

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e54ae0-452e0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e54ae0-452e0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?