On Fri, 12 Mar 2010 12:27:02 +1100 Steven D'Aprano <st...@pearwood.info> wrote:
> On Fri, 12 Mar 2010 11:53:16 am Steven D'Aprano wrote: > > > I have tried to match the behaviour of the built-in unicode as close > > as I am able. See here: > > http://docs.python.org/library/functions.html#unicode > > And by doing so, I entirely forgot that you want to change the default > encoding from 'ascii' to 'utf-8'! Oops. Sorry about that. > > Try changing this bit: > > > else: # Never attempt decoding. > > obj = super(Unicode, cls).__new__(Unicode, string) I get it! The call to new must pass the target class as argument: obj = unicode.__new__(Unicode, string, encoding) ^ while I passed unicode instead. I guess this is the bit that decides on the final class of the return obj. > to this: > > # Untested > else: > if isinstance(string, unicode): > # Don't do any decoding. > obj = super(Unicode, cls).__new__(Unicode, string) > else: > if encoding is None: encoding = cls._ENCODING > if errors is None: errors = cls._ERRORS > obj = super(Unicode, cls).__new__( > Unicode, string, encoding, errors) Thank you again, Steven. Denis ________________________________ la vita e estrany spir.wikidot.com _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor