Re: Sub-classing unicode: getting the unicode value
- From: "Martin v. Löwis" <martin@xxxxxxxxxxx>
- Date: Mon, 31 Dec 2007 17:55:42 +0100
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
.
- References:
- Sub-classing unicode: getting the unicode value
- From: Torsten Bronger
- Re: Sub-classing unicode: getting the unicode value
- From: "Martin v. Löwis"
- Re: Sub-classing unicode: getting the unicode value
- From: Torsten Bronger
- Sub-classing unicode: getting the unicode value
- Prev by Date: PyPy-Sprint 12th-19th January Leysin, Switzerland
- Next by Date: Newbie: Why doesn't this work
- Previous by thread: Re: Sub-classing unicode: getting the unicode value
- Next by thread: evolution-python
- Index(es):
Relevant Pages
|