On 22 Jan 2020, at 14:39, Alex Hall <alex.mojaki@gmail.com> wrote:
You can achieve this now with my executing library: https://github.com/alexmojaki/executing```import ast
import inspect
import executing
def nameof(_):
frame = inspect.currentframe().f_back
call = executing.Source.executing(frame).node
arg = call.args[0]
if isinstance(arg, ast.Name):
return arg.id
elif isinstance(arg, ast.Attribute):
return arg.attr
else:
raise SyntaxError
foo = 3
print(nameof(foo))
print(f"{nameof(ast.Add)} = {ast.Add}")```Other tricks of this nature can be found here: https://github.com/alexmojaki/sorcery