Home:ALL Converter>Python function returning nothing when called

Python function returning nothing when called

Ask Time:2017-12-08T22:29:39         Author:Richard Diertrich

Json Formatter

def my_test(some_function):

    def wrapper():

        num = 10

        if num == 10:
            print("Yes")
        else:
            print("No")

        some_function()

        print("Something is happening after some_function() is called")

    return wrapper


def just_some_function():
    print("Filler text")

my_test(just_some_function)

When I run this script, it should display:

Yes

Filler text

Something is happening after some_function() is called

since my_test(just_some_function) calls my_test, goes through the wrapper function, checks if num == 10, prints "Yes," then goes to just_some_function() (since some_function is the "variable" for the function my_test()), prints "Filler text," then finally ends by printing "Something is happening after some_function() is called." But nothing happens in the console when I run the script.

Author:Richard Diertrich,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/47716365/python-function-returning-nothing-when-called
yy