de la importación anterior print_statement
¿Hay algún equivalente a
from __future__ import print_function that forward-ports the
An answer involving some
ipython magic that lets me print without need of surrounding parens during prototyping is also acceptable.
preguntado el 27 de noviembre de 13 a las 18:11
Some suggestion for IPython
%autocall print "Hi"
Define magic with autocall on
from IPython.core.magic import register_line_magic @register_line_magic def p(line): print(line) p "Hi"
Define magic with autocall off
from IPython.core.magic import register_line_magic @register_line_magic def p(line): print(eval(line)) %p "Again"
You could create a .config/ipython/profile_default/startup/autoprint.py file for you line magic functions.
Provisional answer (A solution that doesn't involve a leading
/ will be preferred.): IPython llama automáticamente an object if line begins with a
/, even if it's indented:
def f(): /print 'foo' f()
IPython also has an
%autocallmagic function that, well, automatically calls functions, so after doing
%autocall 1, mecanografía
print 3in a cell acts like
Also, since it's a function and not a statement, you can simply do
p = print, so later
/p 'foo'calls give you almost
pdb-like behavior (something I was going for but that wasn't explicitly stated in the question).
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas python python-3.x printing or haz tu propia pregunta.
If it's just for the interactive shell, you do not need to
printat all, do you? Just write an expression and you see the result. - tobias_k
You may be looking for Ruby - Ryan Haining
Any downvoters care to suggest question improvements? - beardc
@jazzpi Not a particularly good programming reason... I appreciate the print function's improvements, but I try to reduce # of unnecessary keystrokes for health reasons. Difference between adding the statement/function to an existing line is an extra
Shift-( Ctrl-e Shift-)=6keystrokes for me. I'd grep-change it when I'm done with the program but it makes it easier while developing, especially since I end up deleting most print statements by the end anyways. - beardc
If it's just to reduce typing and strain on wrists, you could also look for a editor / interactive shell that automatically inserts
()after function names. - tobias_k