Ask Your Question
1

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

r"""\
"""

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

Comments

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

r"""
\
"""
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 cloud.sagemath.com, 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
1

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

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"""\
... """
'\\\n'
>>> """\
... """
''

or

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

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

jediknight219 gravatar image

Looks like it is a known IPython bug.

https://github.com/ipython/ipython/is...

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

Stats

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

Seen: 79 times

Last updated: Nov 02 '15