Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

from past import print_statement

Is there some equivalent to from __future__ import print_function that forward-ports the print statement from python 2.x?

An answer involving some ipython magic that lets me print without need of surrounding parens during prototyping is also acceptable.

like image 280
beardc Avatar asked Nov 27 '13 18:11

beardc


1 Answers

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.

like image 145
erny Avatar answered Oct 20 '22 00:10

erny