Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raw strings #56002

Closed
846909323 mannequin opened this issue Apr 7, 2011 · 5 comments
Closed

raw strings #56002

846909323 mannequin opened this issue Apr 7, 2011 · 5 comments
Labels
build The build process and cross-build

Comments

@846909323
Copy link
Mannequin

846909323 mannequin commented Apr 7, 2011

BPO 11793
Nosy @amauryfa, @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2011-04-07.09:36:46.930>
created_at = <Date 2011-04-07.08:48:34.297>
labels = ['build', 'invalid']
title = 'raw strings'
updated_at = <Date 2011-04-08.00:09:26.999>
user = 'https://bugs.python.org/846909323'

bugs.python.org fields:

activity = <Date 2011-04-08.00:09:26.999>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2011-04-07.09:36:46.930>
closer = 'amaury.forgeotdarc'
components = []
creation = <Date 2011-04-07.08:48:34.297>
creator = '846909323'
dependencies = []
files = []
hgrepos = []
issue_num = 11793
keywords = []
message_count = 5.0
messages = ['133199', '133201', '133203', '133210', '133278']
nosy_count = 3.0
nosy_names = ['amaury.forgeotdarc', 'r.david.murray', '846909323']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'compile error'
url = 'https://bugs.python.org/issue11793'
versions = ['Python 3.2']

@846909323
Copy link
Mannequin Author

846909323 mannequin commented Apr 7, 2011

>>> print(r'\')
      
SyntaxError: EOL while scanning string literal
>>> print(r'\'')
\'
>>>

@846909323 846909323 mannequin added the build The build process and cross-build label Apr 7, 2011
@846909323
Copy link
Mannequin Author

846909323 mannequin commented Apr 7, 2011

I think it should be

    >>> print(r'\')
    \
    >>> print(r'\'')
SyntaxError: EOL while scanning string literal
>>>

@amauryfa
Copy link
Member

amauryfa commented Apr 7, 2011

This is by design and documented:
http://docs.python.org/reference/lexical_analysis.html

"""
String quotes can be escaped with a backslash, but the backslash remains in the string; for example, r"\"" is a valid string literal consisting of two characters: a backslash and a double quote; r"\" is not a valid string literal (even a raw string cannot end in an odd number of backslashes).
Specifically, a raw string cannot end in a single backslash (since the backslash would escape the following quote character). Note also that a single backslash followed by a newline is interpreted as those two characters as part of the string, not as a line continuation.
"""

@846909323
Copy link
Mannequin Author

846909323 mannequin commented Apr 7, 2011

Sorry for my poor english and thank you for the answer.
Since I'm a perler, I think this is counterintuitive.
(In perl:
print '\'; #print \
print '\''; #error
print "\""; #print "
print "\"; #error
)

@bitdancer
Copy link
Member

To a pythonista, the perl behavior is counter-intuitive :)

That said, the behavior of r'\' *is* somewhat counter-intuitive. See bpo-1271 for a fairly thorough exploration of why it is the way it is.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build
Projects
None yet
Development

No branches or pull requests

2 participants