unicode(obj, errors='foo') raises TypeError - bug?
Steven Bethard
steven.bethard at gmail.com
Wed Feb 23 11:24:53 EST 2005
Kent Johnson wrote:
> Steven Bethard wrote:
>
>> No, this is documented behavior[1]:
>>
>> """
>> unicode([object[, encoding [, errors]]])
>> ...
>> For objects which provide a __unicode__() method, it will call
>> this method without arguments to create a Unicode string. For all
>> other objects, the 8-bit string version or representation is requested
>> and then converted to a Unicode string using the codec for the default
>> encoding in 'strict' mode.
>> """
>>
>> Note that the documentation basically says that it will call str() on
>> your object, and then convert it in 'strict' mode. You should either
>> define __unicode__ or call str() manually on the object.
>
> Not a bug, I guess, since it is documented, but it seems a bit bizarre
> that the encoding and errors parameters are ignored when object does not
> have a __unicode__ method.
Yeah, I agree it's weird. I suspect if someone supplied a patch for
this behavior it would be accepted -- I don't think this should break
backwards compatibility (much).
STeVe
More information about the Python-list
mailing list