[Python-Dev] PEP 292-related: why string substitution is not the same operation as data formatting

Lalo Martins lalo@laranja.org
Sun, 23 Jun 2002 16:38:41 -0300


On Sun, Jun 23, 2002 at 02:28:20PM -0500, Skip Montanaro wrote:
> 
>     Lalo> These strings may be the result of running some non-string objects
>     Lalo> trough str(foo) - but, we are making no assumptions about these
>     Lalo> objects. Just that str(foo) is somehow meaningful. And, to my
>     Lalo> knowledge, there are no python objects for which str(foo) doesn't
>     Lalo> work.
> 
> Unicode objects can't always be passed to str():
> 
>     >>> str(u"abc")
>     'abc'
>     >>> p = u'Scr\xfcj MacDuhk'
>     >>> str(p)
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in ?
>     UnicodeError: ASCII encoding error: ordinal not in range(128)
> 
> (My default encoding is "ascii".)
> 
> You need to encode Unicode objects using the appropriate charset, which may
> not always be the default.

Valid point but completely unrelated to my argument - just s/str/unicode/
where necessary. '%s' already handles this:

>>> '-%s-' % u'Scr\xfcj MacDuhk'
u'-Scr\xfcj MacDuhk-'

[]s,
                                               |alo
                                               +----
--
  It doesn't bother me that people say things like
   "you'll never get anywhere with this attitude".
   In a few decades, it will make a good paragraph
      in my biography. You know, for a laugh.
--
http://www.laranja.org/                mailto:lalo@laranja.org
         pgp key: http://www.laranja.org/pessoal/pgp

Eu jogo RPG! (I play RPG)         http://www.eujogorpg.com.br/
Python Foundry Guide http://www.sf.net/foundry/python-foundry/