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'
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?
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).