decode(..., errors='ignore') has no effect
Lie Ryan
lie.1296 at gmail.com
Tue Jan 12 09:27:02 EST 2010
On 01/12/10 23:50, Jens Müller wrote:
>> To convert unicode into str you have to *encode()* it.
>>
>> u"...".decode(...) will implicitly convert to ASCII first, i. e. is
>> equivalent to
>>
>> u"...".encode("ascii").decode(...)
>>
>> Hence the error message
>
> Ah - yes of course.
>
> And how can you use the system's default encoding with errors=ignore?
> The default encoding is the one that is used if no parameters are given
> to "encode".
>
> Thanks again!
>>> import sys
>>> sys.getdefaultencoding()
'ascii'
>>> u'M\xfcnchen, pronounced
[\u02c8m\u028fn\xe7\u0259n]'.encode(sys.getdefaultencoding(), 'ignore')
'Mnchen, pronounced [mnn]'
unless this is for debugging, I doubt ignoring error in this particular
case is an acceptable solution (how do you pronounce [mnn]?)
More information about the Python-list
mailing list