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: Literal strings use BS as octal escape character
Type: enhancement Stage: needs patch
Components: Documentation Versions: Python 3.1, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: ajaksu2, brucepeterson, georg.brandl, ncoghlan, nnorwitz
Priority: low Keywords:

Created on 2006-07-27 22:08 by brucepeterson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg60949 - (view) Author: brucepeterson (brucepeterson) Date: 2006-07-27 22:08
Also in 2.4


  Using a literal to hard code a path.  My directory 
happened to start with a number and I couldn't open 
the file due to the bad directory name.  Found that 
the tripple quote was operating as documented.

  I would have at least expected the tripple double 
quotes to not have an escape character.  (Is this a 
pep?)  (From my reading of the Introduction, the 
triple double quotes should act like a raw string 
except that you can have a single double quote 
included in the string.)

-------------
code snippet:
-------------
dir1 = """C:\1stDirecotry"""
dir2 = '''C:\2ndDirecotry'''
dir3 = '''C:\9thDirecotry'''
print dir1, dir2, dir3

C:☺stDirecotry C:☻ndDirecotry C:\9thDirecotry

dir1's format was not expected, dir2's format might be 
expected.

>>> '''\1'''
'\x01'
>>> '''\9'''
'\\9'
msg60950 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-07-29 03:25
Logged In: YES 
user_id=33168

Triple quotes are just like single or double quotes wrt
escaping.  You need to prefix the string with an r: 
r"C:\1stDirecotry" to get what you want.

This is probably documented in many places.  I'm not sure
where you looked or where you expected it to be documented.
 Can you suggest improvements?
msg60951 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2006-08-14 14:53
Logged In: YES 
user_id=1038590

Looking at the tutorial section on strings, it's almost
certainly worth moving the introduction of triple-quoted
string above the introduction of raw strings. At the moment,
I can see how the OP could get the idea that the description
of raw strings applied to triple-quoted strings as well.

The other thing to do would be to explicitly mention
backslash escaping problems in Section 7.2 where it
discusses opening files, and the two possible solutions (use
forward slashes in path literals regardless of platform, or
else used doubled backslashes). I actually thought this was
in the docs already, but it doesn't appear to be in any of
the even vaguely obvious places (the files section in the
tutorial, or the descriptions of file(), open(), file type
or the os.path module in the library reference).
msg84501 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-03-30 04:35
Invalid as bug, keeping open for the doc RFE.
msg84897 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-03-31 20:56
Swapped the sections in r70893.
History
Date User Action Args
2022-04-11 14:56:19adminsetgithub: 43736
2009-03-31 20:56:52georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg84897
2009-03-30 04:35:43ajaksu2setpriority: normal -> low

type: enhancement
assignee: georg.brandl
components: + Documentation, - Interpreter Core
versions: + Python 2.6, Python 3.1, - Python 2.5
nosy: + ajaksu2, georg.brandl

messages: + msg84501
stage: needs patch
2006-07-27 22:08:39brucepetersoncreate