Ask Your Question
1

Bug with raw literals?

asked 2015-11-02 19:19:39 +0100

jediknight219 gravatar image

updated 2016-06-06 21:45:08 +0100

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 19:44:11 +0100 )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 19:46:47 +0100 )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 19:59:31 +0100 )edit

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

jediknight219 gravatar imagejediknight219 ( 2015-11-03 22:57:34 +0100 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2015-11-02 19:56:22 +0100

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

or

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

answered 2015-11-02 20:35:04 +0100

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 19:19:39 +0100

Seen: 787 times

Last updated: Nov 02 '15