"print" magic does not work in Python 3 #2984

Closed
asmeurer opened this Issue Feb 25, 2013 · 8 comments

Projects

None yet

3 participants

Contributor

From the mailing list.

In [10]: @register_line_magic
def print(line):
    __builtin__.print(line)
   ....:

In [11]: %print 1
1

In [12]: print 1
  File "<ipython-input-12-08890221e919>", line 1
    print 1
          ^
SyntaxError: invalid syntax

But you can see that other magics work just fine without the %:

In [13]: timeit 1
100000000 loops, best of 3: 17 ns per loop
Contributor

On an unrelated not, when I went to look up the mailing list link, I noticed that "mailing list" on the homepage links to the dev list. Is the user list defunct, or did you just accidentally drop the user list link?

Contributor

In case it isn't clear, this is all in Python 3.

Owner

(To answer the unrelated note: We're downplaying the user mailing list, with the intention that people ask user questions on Stackoverflow or on the new Hipchat room. But it still exists, and we'll still respond there. My filters route -dev and -user to the same folder, so I usually don't even notice which list things are on)

Contributor

Oh OK. So would you have preferred it if I had asked that question on StackOverflow?

Owner

This one falls near the boundary between 'user question' and 'development
discussion'. As it happened, I think this was better suited to a mailing
list (it would have been fine on -dev, too). But it's not easy to judge
where a question belongs until you know the answer.

On 25 February 2013 23:36, Aaron Meurer notifications@github.com wrote:

Oh OK. So would you have preferred it if I had asked that question on
StackOverflow?


Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/2984#issuecomment-14083496
.

Contributor

OK. I get the feeling that more of the questions I am likely to ask are like that than not, if anything because I am quite willing to submit a pull request if it turns out something is a bug in IPython (and someone points me in the right direction).

Which leads me to my next question: is this something that you might want to include in IPython itself, perhaps as some option to autocall? I imagine it might be quite common among those of us who don't like autocall to still want print to work in Python 3 like it does in Python 2.

Owner

Hmmm...maybe. The question is how much of the old syntax we'd want to
allow. The simple version would only work for a single argument. Multiple
arguments is an obvious extension, but I think it would take several lines
more code. Then there's the magic trailing comma to suppress newline, and
the ugly 'print >>target, object' syntax. Plus, of course, it mustn't
interfere with the real print() function.

We might also prefer not to have it on by default, for the same reason that
we turned autocall off: to avoid confusing people about how Python syntax
works. Making print() a normal function means one less piece of syntax to
learn.

I think I'd suggest what we've said about quite a few feature ideas
recently: make a decent implementation, let people know about it, and see
how much popularity it gets.

On 26 February 2013 00:56, Aaron Meurer notifications@github.com wrote:

OK. I get the feeling that more of the questions I am likely to ask are
like that than not, if anything because I am quite willing to submit a pull
request if it turns out something is a bug in IPython (and someone points
me in the right direction).

Which leads me to my next question: is this something that you might want
to include in IPython itself, perhaps as some option to autocall? I imagine
it might be quite common among those of us who don't like autocall to still
want print to work in Python 3 like it does in Python 2.


Reply to this email directly or view it on GitHubhttps://github.com/ipython/ipython/issues/2984#issuecomment-14086343
.

Owner

I'm going to close this, as it doesn't look like it's going anywhere. It's working as designed in that automagics are only used when they're not shadowed by a normal function.

@takluyver takluyver closed this Jul 5, 2013
@minrk minrk added this to the no action milestone Mar 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment