[Python-Dev] Strings: '\012' -> '\n'

Ka-Ping Yee ping@lfw.org
Tue, 16 Jan 2001 02:47:02 -0800 (PST)


On Mon, 15 Jan 2001, Ka-Ping Yee wrote:
> On Mon, 15 Jan 2001, Guido van Rossum wrote:
> > Originally, using \x for these was impractical (at least) because of
> > the stupid gobble-up-everything-that-looks-like-a-hex-digit semantics
> > of the \x escape.  Now we've fixed this, I agree.
> 
> Oh, now i understand.  Good point.  I'll update the patch to do hex.

I assume you would like Unicode strings to do the same (\n, \t, \r,
and \xff rather than \377).

Guido, do you have a Pronouncement on \v, \f, \b, \a?

By the way, why do Unicode escapes appear in capitals?

    >>> u'\uface'
    u'\uFACE'

(If someone tells me that there happens to be a picture of a face at
that code point, i'll laugh.  Is there a cow at \uBEEF?)

Does anyone care that \x will be followed by lowercase and \u by uppercase?

I noticed that the tutorial claims Unicode strings can be str()-ified
and will encode themselves using UTF-8 as default.  But this doesn't
actually work for me:

    >>> us = u'\uface'
    >>> us
    u'\uFACE'
    >>> str(us)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    UnicodeError: ASCII encoding error: ordinal not in range(128)
    >>> us.encode()
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    UnicodeError: ASCII encoding error: ordinal not in range(128)
    >>> us.encode('UTF-8')
    '\xef\xab\x8e'

Assuming i have understood this correctly, i have submitted a patch
to correct tut.tex.


-- ?!ng