Related question here, but I'm not able to translate the solution (i.e. use inspect
) in actual code. In addition, the cited question is 5 years old and new methodologies might have become available.
locals() is concise and great, but it returns a dictionary that is affected by what happens in the local environment. However, the solution should be independent on what's going on in the local environment.
def foo(a=1):
return locals()
foo() # returns {'a': 1}
def bar(a=1):
a = 2
return locals()
bar() # returns {'a': 2}
def solution(a=1):
a = 2
return # DO: RETURN SOMETHING
solution() # should returns {'a': 1}