[Python-Dev] String literals escape sequences
Guido van Rossum
guido at python.org
Sat Jul 10 05:38:24 CEST 2004
> The python language reference says:
> " Unlike Standard C, all unrecognized escape sequences are left in the
> string unchanged, i.e., /the backslash is left in the string/. (This
> behavior is useful when debugging: if an escape sequence is mistyped,
> the resulting output is more easily recognized as broken.)"
> It seems to me that a syntax error of some kind would be even more
> useful. For instance if one is dealing with an extremely large output
> they might be able to miss a single missing \t or \n.
Well, maybe then they didn't care either way. :-)
> Another problem is some beginners seem to be very confused between print
> '\n' and print '\l'
I've never heard of this. Where would \l come from?
> Also, what happens when people perhaps want '\l' and instead of using
> '\\l' type '\l' by accident, and their output looks fine, but later down
> the road it is decided '\l' should be an escape sequence.
> Is there a very good reason for this behavior?
The paragraph in the reference manual you give presents the original
reason. Right now, changing this would break too much code to
consider it. We might consider deprecating this use in 2.4, adding
warnings in 2.5, and making it illegal in 3.0. But I'm not sure it's
worth the bother.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev