I'd like to print all the variables and their values defined in a cell without having to do
print('x:', x)
print('y:', y)
print('z:', z)
...
is there something like:
%p x y z
and it will do the equivalent of the above?
I'd like to print all the variables and their values defined in a cell without having to do
print('x:', x)
print('y:', y)
print('z:', z)
...
is there something like:
%p x y z
and it will do the equivalent of the above?
You can create a line magic which will do that.Something like below
from IPython.core.magic import register_line_magic
@register_line_magic
def p(args):
for key in args.split(" "):
print globals()[key]
With ipython notebook you can use:
#without turning on %automagic
%who
#with turning on %automagic
who
This will display all variables names held in memory
#without turning on %automagic
%whos
#with turning on %automagic
whos
This will display variable names and their values
References:
x = 'test1'
y = 'test2'
z = 'test3'
print('x: %s, y: %s, z: %s'%(x, y,z))
if x, y, z variables is integers, You should use %d instead of %s.