On Jul 24, 2005, at 5:00 AM, Bengt Richter wrote:
> Actually, it's not just the "magic" methods. [...]
Thanks for the clarification/explanation =)
> This looks a little strange because the repr of the bound method
> includes a repr of the thing bound to,
> which returns the Edit/View presentat
On Sat, 23 Jul 2005 10:59:56 -0400, "Jeffrey E. Forcier" <[EMAIL PROTECTED]>
wrote:
>Thanks for all the additional replies thus far!
>
>Apparently the issue, as stated implicitly or explicitly by most of
>you, is that new-style class instances essentially defer their magic
>methods to the cla
Paolino wrote:
> Little less ugly:
> In [12]:class A(object):
>: def __str__(self):return self.__str__()
>: def str(self):return 'ciao'
>: def setStr(self):self.__str__=self.str
>:
>
> In [13]:a=A()
>
> In [14]:a.setStr()
>
> In [15]:str(a)
> Out[15]:'
Thanks for all the additional replies thus far!
Apparently the issue, as stated implicitly or explicitly by most of
you, is that new-style class instances essentially defer their magic
methods to the class's static versions of same. This is good to know :)
Ironically, the reason I'm using new
Jeffrey E. Forcier wrote:
> ...
> However, you appear to be correct, and the docs appear to be confused:
> class MyClass(object):
> def edit(self):
> return "I'm in edit mode"
> def setEdit(self):
> MyClass.__str__ = self.edit
> ...
> Either way, gues
Little less ugly:
In [12]:class A(object):
: def __str__(self):return self.__str__()
: def str(self):return 'ciao'
: def setStr(self):self.__str__=self.str
:
In [13]:a=A()
In [14]:a.setStr()
In [15]:str(a)
Out[15]:'ciao'
The point is str(ob) builtin l
ncf wrote:
> Well, suffice to say, having the class not inherit from object solved
> my problem, as I suspect it may solve yours. ;)
Actually, I did a bit of experimenting. If the __str__ reassignment
worked as intended, it would just cause an infinite recursion.
To paste the class definition a
In trying to develop a protocol for a current app I'm working on, I was
using classes which inherited from object for my core packet, and using
str(Message) to convert it to an encoded packet. However, I found that
this did not work, and it drove me insane, so in a test file, I wrote
the following
On Jul 22, 2005, at 7:46 PM, Michael Hoffman wrote:
> I'm too tired and/or lazy to check, but I believe str() is calling
> MyClass.__str__(testObject) as it is supposed to rather than
> testObject.__str__() as you say it is supposed to. ;-)
>
> Someone else or Google can probably enlighten you on
Jeffrey E. Forcier wrote:
> In other words, str() is _NOT_ apparently calling .__str__ as
> it's supposed to! However, calling __str__ directly (which, yes, you're
> not supposed to do) does work as expected:
I'm too tired and/or lazy to check, but I believe str() is calling
MyClass.__str__(
I am attempting to write a class whose string representation changes
in response to external stimuli. While that effect is obviously
possible via other means, I attempted this method first and was
surprised when it didn't work, so I now want to know why :)
Given the following class definitio
11 matches
Mail list logo