Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


print(…, sep=…) raises SyntaxError #777

lebigot opened this Issue · 3 comments

2 participants

Eric O. LEBIGOT (EOL) Thomas Kluyver

With IPython 0.11 (Mac OS X Lion, installed via Fink) and Python 2.7, the print() function raises a strange SyntaxError:

In [2]: from __future__ import print_function
In [3]: print("Helloe", "lkj", sep="lkj")
  File "<ipython-input-3-ff000ce1a53b>", line 1
    print("Helloe", "lkj", sep="lkj")
SyntaxError: invalid syntax

The name print seems to be correctly defined:

In [6]: print?
Type:       builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form:<built-in function print>
Namespace:  Python builtin
print(value, ..., sep=' ', end='\n', file=sys.stdout)

Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep:  string inserted between values, default a space.
end:  string appended after the last value, default a newline.

I'm not sure whether this matters, but the failure happens with both autocall on and off.

Thomas Kluyver

Hmm, I think I can see where this is coming from. We parse the code with ast.parse before we compile it. __future__ imports from previous cells are stored as flags to pass to the compiler, but they're not passed to ast.parse, so it is still parsing print as a statement.

I think I can see a way round it - I'll hopefully have a go later today.

Thomas Kluyver takluyver was assigned
Thomas Kluyver takluyver referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Thomas Kluyver

See PR #784. Sorry I didn't get round to it on Thursday - it's been a busy few days.

Thomas Kluyver takluyver closed this in e783b1c

Thanks, that's great!

Brian E. Granger ellisonbg referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
matthew von rocketstein mattvonrocketstein referenced this issue from a commit in mattvonrocketstein/ipython
Thomas Kluyver takluyver Parse user code to AST using compiler flags.
Closes gh-777.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.