[Tutor] use of __new__

Alan Gauld alan.gauld at btinternet.com
Fri Mar 12 01:26:19 CET 2010


"spir" <denis.spir at gmail.com> wrote


> The issue is the object (self) is then a unicode one instead of my own 
> type.

I think you need to modify self in __new__

>
> class Unicode(unicode):
>    Unicode.FORMAT = "utf8"
>    def __new__(self, text, format=None):
>        # text can be str or unicode
>        format = Unicode.FORMAT if format is None else format
>        if isinstance(text,str):
>            text = text.decode(format)

              self = text.decode(format)

But I've only used __new__ once before so am no expert!

Alan G. 




More information about the Tutor mailing list