Re: Sub-classing unicode: getting the unicode value
- From: Gabriel Genellina <gagsl-py2@xxxxxxxxxxxx>
- Date: Sun, 30 Dec 2007 12:44:09 -0800 (PST)
On 30 dic, 17:25, Torsten Bronger <bron...@xxxxxxxxxxxxxxxxxxxxx>
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.
Are you sure you *really* want to inherit from unicode? Don't you want
to store an unicode object as an instance attribute?
Unfortunately, unicode objects don't have a __unicode__ method.
Because it's not needed; unicode objects are already unicode objects,
and since they're immutable, there is no need to duplicate them. If it
existed, would always return self.
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)
How does my object get its own value?
"its own value" is the instance itself
--
Gabriel Genellina
.
- Follow-Ups:
- Re: Sub-classing unicode: getting the unicode value
- From: Torsten Bronger
- Re: Sub-classing unicode: getting the unicode value
- References:
- Sub-classing unicode: getting the unicode value
- From: Torsten Bronger
- Sub-classing unicode: getting the unicode value
- Prev by Date: Re: Bizarre behavior with mutable default arguments
- Next by Date: Re: Bizarre behavior with mutable default arguments
- Previous by thread: Sub-classing unicode: getting the unicode value
- Next by thread: Re: Sub-classing unicode: getting the unicode value
- Index(es):
Relevant Pages
|