It would be very useful for debugging to have a function like thus:
a = np.arange(20)
debug_print(a)
The above should print
variable: a
val: [...]
thanks a lot.
It would be very useful for debugging to have a function like thus:
a = np.arange(20)
debug_print(a)
The above should print
variable: a
val: [...]
thanks a lot.
Try following code:
import inspect
import re
def debug_print(*args):
lines = ''.join(inspect.stack()[1][4])
matched = re.search('debug_print\((.*?)\)', lines).group(1)
names = map(str.strip, matched.split(','))
for name, value in zip(names, args):
print('{} = {}'.format(name, value))
a = 1
b = 2
debug_print(a, b)
debug_print('a')
debug_print('a,aa') # Not work well for this case.