python 2.7 and unicode (one more time)

Peter Otten __peter__ at web.de
Thu Nov 20 10:40:00 EST 2014


random832 at fastmail.us wrote:

> On Thu, Nov 20, 2014, at 07:35, Peter Otten wrote:
>> >>> "%s nötig %s" % (u"üblich", u"ähnlich")
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4:
>> ordinal not in range(128)
> 
> This is surprising to me - why is it trying to decode the format string,
> rather than encode the arguments?

Probably to make it easier to mix byte and unicode strings. In hindsight it 
may not have been a good idea, but it had the potential to save some memory.

I think that you may get a Unicode/Encode/Error when you try to /decode/ a 
unicode string is more confusing...





More information about the Python-list mailing list