possible bug in pdb (escape sequences)


Pdb is Python’s console-line debugger. It’s not working on my machine for filenames that start with a string escape sequence, if I use their fully qualified path. Here is the error:

the string seems to have eaten my “\t”, but it seems to be present in the ‘cmd’ variable. It works on non-Panda Python 2.5, filename only with no path, filenames with path if they don’t start with an escape code, filenames that start with an escape code if they don’t have a space in them or the escape code is upper-case, and in directories that start with T, such as:

Also, no it is not my editor:

Where did the filename come from? Did you type it, or was it read from some source? It appears that it is interpreting the sequence \t as a tab character, which is normal Python behavior when parsing a quoted string. If you want it to parse a literal backslash, you must double it, e.g. \t.

Or, you could use the forward slash, which also works on Windows, and is less likely to confuse Python: /t.


I was using user-configured tools in my editor when I found it. After all those variations, which I figure I didn’t need to post, I tried the command line too. So, from a command line (which I attempted to imply was the last quote above), “point-blank” as they say:

The only difference in whether the error occurs is whether I use a ‘t’ (first) or a ‘T’ for the first character in the filename.

Right, the backslash should always be escaped (doubled) when it appears, but Python has the “helpful” feature of interpreting a backslash that is not followed by a known backslash escape character as a literal backslash. Since lowercase ‘t’ is a known backslash escape character, but capital ‘T’ is not, it means that \T is interpreted as a literal backslash followed by the letter T, but \t is interpreted as a tab character.

This only contributes to confusion, IMHO. To play it safe, you should always double a backslash: \T and \t are both interpreted the same way, as a single backslash followed by a letter.


I appear to have been pretty careless in the above report, which caused it to appear to be related to Panda’s distribution of Python 2.6. I have learned that the problem occurs on 2.5, and consistently with directories, not just filenames.

It’s just baffling I never encountered it… with all the combinations.

So I will have to do something with the user-configured tools. The argument macros don’t include a double-slashed or a forward-slashed path & filename, so I’ll have to improvise.