Sub-classing unicode: getting the unicode value

Torsten Bronger bronger at physik.rwth-aachen.de
Sun Dec 30 16:59:35 EST 2007


Hallöchen!

Gabriel Genellina writes:

> On 30 dic, 19:08, Torsten Bronger <bron... at physik.rwth-aachen.de>
> wrote:
>
>> [...]
>>
>> But then it is not unicode but Excerpt which I don't want.  The
>> idea is to buffer the unicode representation in order to gain
>> efficiency.  Otherwise, a lot of unicode conversion would take
>> place.
>
> Still I don't see why you want to inherit from unicode.

Because I want to use some of its functionality and override the
rest.  And now, all I want to do is to convert the current Excerpt
object into a real unicode object that represents the same string.
Outside the object, I'd simply say unicode(my_excerpt), but this
doesn't work within the __unicode__ method of Excerpt.

> [...]
>
>>>> However, unicode(super(Excerpt, self)) is also forbidden
>>>> because super() allows attribute access only (why by the way?).
>>>
>>> (because its purpose is to allow cooperative methods in a
>>> multiple inheritance hierarchy)
>>
>> It would be more useful, however, if it returned full-fledged
>> objects.  Or if there was another way to get a full-fledged
>> mother object.
>
> There is no such "mother object", in Python an instance is usually
> a whole unique object, not an onion-like structure.

But the mother object could be created.

I simply see no reason why "super(MotherClass, self)[key]" must
fail, except maybe because it's harder to realise in the underlying
implementation of Python.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
                                      Jabber ID: bronger at jabber.org
               (See http://ime.webhop.org for further contact info.)



More information about the Python-list mailing list