Created
October 24, 2015 18:33
-
-
Save anishpatel/e32f9cdc1df55692f418 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
def echoeval(expr_str): | |
global sys, pprint | |
try: sys | |
except NameError: import sys | |
try: pprint | |
except NameError: from pprint import pprint | |
calling_frame = sys._getframe().f_back | |
print(expr_str, '=', end=' ') | |
pprint(eval(expr_str, calling_frame.f_locals, calling_frame.f_globals)) | |
if __name__ == '__main__': | |
num = 3.14 | |
class A: | |
hello = 'Hello World!' | |
def f(x): | |
echoeval('num') | |
echoeval('num * 2') | |
echoeval('A.hello') | |
echoeval('x') | |
f([1, 2, 3]) | |
# Output: | |
# num = 3.14 | |
# num * 2 = 6.28 | |
# A.hello = 'Hello World!' | |
# x = [1, 2, 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this Log function:
Thank you!!