Unrecognized escape sequences in string literals

Duncan Booth duncan.booth at invalid.invalid
Mon Aug 10 05:34:38 EDT 2009


Douglas Alan <darkwater42 at gmail.com> wrote:

> "\xba" isn't an escape sequence in any other language that I've used,
> which is one reason I made this error... Oh, wait a minute -- it *is*
> an escape sequence in JavaScript. But in JavaScript, while "\xba" is a
> special character, "\xb" is synonymous with "xb".
> 

"\xba" is an escape sequence in c, c++, c#, python, javascript, perl and 
probably many others.

"\xb" is an escape sequence in c, c++, c# but not in Python, Javascript, or 
Perl. Python will throw ValueError if you try to use "\xb" in a string, 
Javascript simply ignores the backslash.

> The fact that every language seems to treat these things similarly but
> differently, is yet another reason why they should just be treated
> utterly consistently by all of the languages: I.e., escape sequences
> that don't have a special meaning should be an error!

It would be nice if these things were treated consistently, but they aren't 
and it seems unlikely to change.



-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list