This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: string literal documentation differs from implementation
Type: Stage:
Components: Documentation Versions: Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: dalke, georg.brandl, gvanrossum
Priority: normal Keywords: easy

Created on 2008-01-22 03:28 by dalke, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg61484 - (view) Author: Andrew Dalke (dalke) * (Python committer) Date: 2008-01-22 03:28
The reference manual documentation for raw string literals says

"""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."""

This is not the observed behavior.

>>> s = """ABC\
... 123"""
>>> s
'ABC123'
>>> 

Line continuations are ignored by triple quoted strings.



In addition, the reference manual documentation for "\x" escapes says

| ``\xhh``        | Character with hex value *hh*   | (4,5) |

where footnote (4) stays

   Unlike in Standard C, at most two hex digits are accepted.

However, the implementation requires exactly two hex digits:

>>> "\x41"
'A'
>>> "\x4."
ValueError: invalid \x escape
>>> "\x4" 
ValueError: invalid \x escape
>>>
msg61485 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-22 04:19
Your example does not use a "raw" string -- a raw string has an 'r' in 
front of the opening string quotes.  Try this instead:

>>> s = r"""a\
... b"""
>>> s
'a\\\nb'

Your second issue is correct -- the definition of \xXX in Python has 
changed over the years to what you observed.  I still don't think it 
matches the C standard though. :-)

Assigning to Georg for a doc fixup.  I'm assuming this is also for 
higher Python versions.
msg61486 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-01-22 07:54
Fixed in r60193, r60194 (2.5).
History
Date User Action Args
2022-04-11 14:56:30adminsetgithub: 46197
2008-01-22 07:54:41georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg61486
2008-01-22 04:19:14gvanrossumsetkeywords: + easy
assignee: georg.brandl
messages: + msg61485
nosy: + georg.brandl, gvanrossum
2008-01-22 03:28:40dalkecreate