Ask Your Question

Bug with raw literals?

asked 2015-11-02 12:19:39 -0600

jediknight219 gravatar image

updated 2016-06-06 14:45:08 -0600

FrédéricC gravatar image

On cloud.sagemath, the following is interpreted as an empty string


According to the python docs, Section 2.4.1 of the language specification:: "Note also that a single backslash followed by a newline is interpreted as those two characters as part of the literal, not as a line continuation."

Is this a bug? Or am I missing something?

edit retag flag offensive close merge delete


Apparently it only happens on the first line. The following works fine.

jediknight219 gravatar imagejediknight219 ( 2015-11-02 12:44:11 -0600 )edit

On cloud.sagemath the output for me is: '\\\n', however on my local sage and sagecell the output is ''. That is a bit strange.

fidbc gravatar imagefidbc ( 2015-11-02 12:46:47 -0600 )edit

I'm on, running a Jupyter notebook, running the Python 2 kernel. I tried changing to Python 3, but to no avail.

jediknight219 gravatar imagejediknight219 ( 2015-11-02 12:59:31 -0600 )edit

On cloud.sagemath it works in a sage worksheet, but not a Jupyter notebook.

jediknight219 gravatar imagejediknight219 ( 2015-11-03 15:57:34 -0600 )edit

2 answers

Sort by » oldest newest most voted

answered 2015-11-02 12:56:22 -0600

vdelecroix gravatar image

By definition the r before the string means that the backslashes are automatically escaped. Note the difference

$ python
Python 2.7.9 (default, Mar  1 2015, 12:57:24) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> r"""\
... """
>>> """\
... """


>>> r"\n"
>>> "\n"
edit flag offensive delete link more

answered 2015-11-02 13:35:04 -0600

jediknight219 gravatar image

Looks like it is a known IPython bug.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-11-02 12:19:39 -0600

Seen: 131 times

Last updated: Nov 02 '15