Re: Sub-classing unicode: getting the unicode value



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
.



Relevant Pages

  • Re: Sub-classing unicode: getting the unicode value
    ... Gabriel Genellina writes: ... get the actual value of the instance, i.e. the unicode string: ... The "actual value of the instance", given that it inherits from ...
    (comp.lang.python)
  • Re: Writing UTF-8 string to UNICODE file
    ... > I am having no fun at all trying to write utf-8 strings to a unicode file. ... it were a distinct encoding. ... is a byte stream and unicode has nothing to do with bytes. ... If you write a unicode string to something that wants a byte stream, ...
    (comp.lang.python)
  • Re: Sorting a list of Unicode strings?
    ... Unicode strings, and I want to sort these alphabetically, then it ... places those that begin with unicode characters at the bottom. ... different sorting criteria; indeed, in some countries, different sorting ... The .translate method of Unicode string objects may ...
    (comp.lang.python)
  • Best ways of managing text encodings in source/regexes?
    ... those strings contain only ASCII or ISO-8859-1 chars? ... standard library modules such as re don't declare an encoding, ... then read the source file into a unicode string with codecs.read, ...
    (comp.lang.python)
  • Re: Convert DOS Cyrillic text to Unicode
    ... > You would use Encoding.GetEncoding to get the DOS Cyrillic Encoding ... > Encoding.GetString to convert to a Unicode String. ... > Dim bytesAs Byte ...
    (microsoft.public.dotnet.languages.vb)