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

Ka-Ping Yee ping@lfw.org
2001年1月16日 02:47:02 -0800 (PST)


On 2001年1月15日, Ka-Ping Yee wrote:
> On 2001年1月15日, 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

AltStyle によって変換されたページ (->オリジナル) /