How can I call an inner function within a Python module?
I have created a Python module. Within this module, there is a function. Within this function, there is a nested function. I saved the Python file with the name custom_module.py.
I have then called this module using the statement import custom_module.
I have then tried to call the nested function. I did this using the statement custom_module.outer_function().inner_module().
This has not called the function correctly. How could I call the inner function from within a Python module, or will I need to create separate functions and not use nested functions.
I do not always want to call the inner functions when I run the outer function.
An example of a file named module.py:
def outerFunction():
print("This is the outer function")
def innerFunction():
print("This is the inner function")
An example of the main file:
import module
module.outerFunction().innerFunction()
returning the inner function in the outer function? If not, this simply won't be possible, regardless of if it's in a module or not.returned and assigned to something.innerFunctionis such a variable. You canreturnit withreturn innerFunctionand capture it withmy_variable = outerFunction(), and then call it withmy_variable(). That is what @Chris 's answer is doing. Or do it in one call withouterFunction()().