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

Guido van Rossum guido@python.org
Tue, 16 Jan 2001 09:06:23 -0500


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

Yeah.

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

Practicality beats purity: these will remain octal.

> By the way, why do Unicode escapes appear in capitals?
> 
>     >>> u'\uface'
>     u'\uFACE'

Could it be just that that's what Unicode folks are expecting?

> (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?)

I'm laughing even though I don't see pictures. :-)

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

It's mildly weird, and I think hex escapes in lowercase are more
Pythonic than in upper case.

> 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.

Yeah, I guess that part of the tutorial was written before we changed
our minds about this. :-(

--Guido van Rossum (home page: http://www.python.org/~guido/)