[IPython-User] print "autocall" in Python 3
Aaron Meurer
asmeurer@gmail....
Mon Feb 25 17:01:53 CST 2013
On Mon, Feb 25, 2013 at 4:03 AM, Thomas Kluyver <takowl@gmail.com> wrote:
>
> On 25 February 2013 09:45, Aaron Meurer <asmeurer@gmail.com> wrote:
>>
>> In [12]: print 1
>> File "<ipython-input-12-08890221e919>", line 1
>> print 1
>> ^
>> SyntaxError: invalid syntax
>
>
> This does seem like a bug. It's not getting translated into the call with
> the magic (use hist -t to see translations). I guess something must be
> treating it as Python 2 syntax. File a bug so we don't forget it.
https://github.com/ipython/ipython/issues/2984
>
> If it helps, you can force automatic brackets using a slash:
>
> In [1]: /print 123 456
> 123 456
>
>
>>
>> Error in generated code:
>> def print(line):
>> return _call_(_func_, line)
>>
>> File "<string>", line 1
>> def print(line):
>> ^
>> SyntaxError: invalid syntax
>
>
> (Just tested, this error is only when running in Python 2, yes?)
Yes.
>
> This is because of the decorator library we're using. In order to preserve
> the function signature, it actually assembles a new function as a string,
> and calls compile() on it. Of course, in that context,
> __future__.print_function is not in effect, so you can't redefine print.
>
> Short of dropping the decorator library, I don't think there's much we can
> do about that. Adding a condition to check the Python version first should
> work.
>
> Finally, don't forget that you'll need to evaluate the input, otherwise...
Oh, I guess I misunderstood the API. What is the proper way to do that?
Aaron Meurer
>
> In [1]: a = 42
>
> In [2]: %print a
> a
>
> Best wishes,
> Thomas
>
>
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
More information about the IPython-User
mailing list