A bit of a niche question, but here goes: is there a way a Python function can get access to the name of a variable being passed into it--specifically, that variable's name in the scope in which the function is called? For example, something like this:
def print_name_and_value(x):
name_x = {this is the part I don't know}
print(f"Variable {name_x} has value {x}.")
foo = 2
print_name_and_value(foo)
...should print the text "Variable foo has value 2". I can imagine two possible ways this can go: either pass in the variable itself, and somehow the function fetches the name of that variable from the external scope. Or, you pass in a string with the variable name ("foo"), and somehow the function fetches the value of the variable with that name from the external scope. The idea is to avoid manually passing in both foo (the variable) and "foo" (the string) as arguments. Is this possible or is it Python black magic?