Escapes???

Johannes Stezenbach yawyi at gmx.de
Fri Jun 2 17:01:29 EDT 2000


Aahz Maruch <aahz at netcom.com> wrote:
>In article <8h8lkt$rb7$1 at nnrp1.deja.com>, Arinté  <jamarijr at my-deja.com> wrote:
>>You must be using a different version or something.  I use the python
>>gui thing and did this
>>print "\x1ba"
>>got a funny circle
>>print "\x1b a"
>>[] a   < not an exact represetation.
>>But, it still points out the fact that python is picking up the 1 b and
>>a.
>
>Ah.  Python appears to allow three-digit hex numbers.  I guess you'll
>have to paste the string together, character by character.

Expecting this to be a bug in the Python string parser, to my surprise
I found that the Python language reference says in section 2.4.1
about string literals (section numbers from 1.5.2 docs):

"""... an unlimited number of hex digits is taken to be part
of the hex escape (and then the lower 8 bits of the resulting hex
number are used in 8-bit implementations).
"""

Using the information from section 2.4.2 about string literal
concatenation you can write:
   print "\x1b" "a"


I'm curious to know which platform has characters with more
than 8 bits, except for Unicode in Python 1.6, of course, but
there's \u for that purpose -- with \x1234 being equivalent to
\u1234 in u"" strings:
>>> "\x1234"
'4'
>>> "\u1234"
'\\u1234'
>>> u"\x1234"
u'\u1234'
>>> u"\u1234"
u'\u1234'
>>> 

Are more-than-two-digit hex escapes obsolete? Were they ever
useful? Are they part of devilish plan to confuse former
C programmers? Is \u vs. \x a symptom of TMTOWTDI?

Johannes




More information about the Python-list mailing list