Created
June 8, 2022 15:47
-
-
Save Tishka17/f143cdc0a6c80f7dd7e2d6ebbc441b05 to your computer and use it in GitHub Desktop.
Python code without any return
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### library mode | |
import inspect | |
def res_var_name(fname): | |
return f"_{fname}_result_" | |
def result(value, offset=1): | |
stack = inspect.stack() | |
calframe = stack[offset] | |
module = inspect.getmodule(calframe.frame) | |
fname = calframe.function | |
setattr(module, res_var_name(fname), value) | |
def load_result(func): | |
result( | |
getattr(inspect.getmodule(func), res_var_name(func.__name__)), | |
offset=2, | |
) | |
#### user code | |
def foo(arg): | |
result(arg + 1) | |
def bar(): | |
foo(100) | |
load_result(foo) | |
print(_bar_result_) | |
bar() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment