I tried to search the question for a bit but can't find a actual answer. I'm trying to implement a function (magic_debug) so that when called in another function (somefunc), it can access the variable within the somefunc and print it out as follow:
def magic_debug(s, *args, **kwargs):
s2 = s.format(x=x,y=y,z=args[0])
print(s2)
def somefunc():
x = 123
y = ['a', 'b']
magic_debug('The value of x is {x}, and the list is {y} of len {z}', len(y))
somefunc()
the expected output --> The value of x is 123, and the list is ['a', 'b'] of len 2