python 2.7 and unicode (one more time)

Ian Kelly ian.g.kelly at gmail.com
Thu Nov 20 19:09:35 CET 2014


On Thu, Nov 20, 2014 at 11:06 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Thu, Nov 20, 2014 at 10:42 AM,  <random832 at fastmail.us> wrote:
>> and it means you can't safely
>> blindly use %s with an unknown object.
>
> You can't safely do this anyway. Whether it's %s with a str and a
> unicode, or %s with a unicode and a str, *something* is going to have
> to be implicitly encoded or decoded, and if ascii doesn't happen to be
> the correct encoding then the result will be either an error or a
> silent failure.

Also note that if you use %r instead of %s, you'll get the result you
want (although the unicode string will be quoted rather than encoded).



More information about the Python-list mailing list