Re: Sub-classing unicode: getting the unicode value



How does my object get its own value?
def __unicode__(self):
return unicode(self)

I get an endless recursion with this.

I see. That worked fine in Python 2.4, but give a stack overflow
in Python 2.5.

Depending on your exact class definition, something like

return super(unicode, self).__getitem__(slice(0,len(self)))

should work.

I must admit, though, that I probably overestimate the costs
connected with unicode(my_excerpt) because Gabriel is probably right
that no real conversion takes place. A mere attribute lookup may
still be cheaper, but only very slightly.

I don't understand that remark. To implement the conversion in the
way you want it to be, it definitely needs to produce a copy of
self.

Regards,
Martin
.



Relevant Pages

  • Re: painful debugging: techniques?
    ... Perhaps not so much a trick as much as experience, ... with Python a bit, you'll find that any time you see something like ... depending on how much new code you had written before the error ... started happening could help bound your search, ...
    (comp.lang.python)
  • Dependencies
    ... of my ports are listed as depending on python, including several PERL ...
    (comp.unix.bsd.freebsd.misc)
  • Building a web questionnaire, can it be done in Python ?
    ... I'm considering building a web questionnaire in Python. ... I've made several desktop applications in Python / wxPython, ... The questions can have different forms, multiple choice, multiple choice with multiple answers, but also things like sliders. ... Depending on answers to previous questions, ...
    (comp.lang.python)
  • Re: How to read one byte at a time in Python?
    ... > do we have such a function in python? ... inf = open ... Depending on the meaning of the word 'byte' in your question, ...
    (comp.lang.python)
  • Re: Python in a desktop environment
    ... which you wanted to be cross platform (at least Mac and Windows), ... Depending on what exactly you're trying to do, a pure python solution ... Your question is kind of vague, ...
    (comp.lang.python)