Re: Format strings

Josef Spillner <[email protected]> Fri, 25 Nov 2005 19:45:15 +0100
Newsgroups gmane.comp.python.internationalization
Message-ID <[email protected]>
El Viernes, 25. Noviembre 2005 19:14, escribi=F3:
> I don't see the relationship to Python in that posting...

The following should demonstrate it:

# -*- coding: utf-8 -*-
print "'%2s'" % "a"
print "'%2s'" % "=E1"
print "'%2s'" % u"=E1"

In the second case, while the string literal is recognized as utf-8 (thus t=
wo =

bytes being one character in this case), it eats the two character format =

string alone and doesn't leave any space for the empty character.

Note that if the file encoding is not given, then it would display as '=C3=
=A1', =

which is correct under the circumstances.

But in general, I don't see why line two in the example above cannot be lik=
e =

line three. It is not intuitive to only have one character printed as oppos=
ed =

to the two that are requested from the format string.

Actually, a related question: why are string objects ASCII by default inste=
ad =

of the encoding specified at the beginning of the file? Are there any plans =

to merge the "unicode" string functionality into basic strings?

Josef