Print expression and also echo it
问题 I mean to define a function print_echo that replaces print , such that in addition to printing the result of an expression it prints the expression itself. If I simply pass the expression as a string and use eval inside print_echo , it will not know any variable local to the caller function. My current code is def print_echo( expr ) : result = eval( expr ) print( expr + ' => ' + str( result ) + ' ' + str( type( result ) ) ) return But when using def my_func( params ) : a = 2 print_echo( "a" )