Skip to content

Instantly share code, notes, and snippets.

@Tishka17
Created June 8, 2022 15:47
Show Gist options
  • Save Tishka17/f143cdc0a6c80f7dd7e2d6ebbc441b05 to your computer and use it in GitHub Desktop.
Save Tishka17/f143cdc0a6c80f7dd7e2d6ebbc441b05 to your computer and use it in GitHub Desktop.
Python code without any return
#### 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