Sub-classing unicode: getting the unicode value

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


Hallöchen!

Gabriel Genellina writes:

> On 30 dic, 17:25, Torsten Bronger <bron... at physik.rwth-aachen.de>
> wrote:
>
>> I sub-classed unicode in an own class called "Excerpt", and now I
>> try to implement a __unicode__ method.  In this method, I want to
>> get the actual value of the instance, i.e. the unicode string:
>
> The "actual value of the instance", given that it inherits from
> unicode, is... self.

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.

> Are you sure you *really* want to inherit from unicode? Don't you
> want to store an unicode object as an instance attribute?

No, I need many unicode operations (concatenating, slicing, ...).

> [...]
>
>> 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.

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