![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.python archive"Aliasing" an object's __str__ to a different method
From: Jeffrey E. Forcier <jforcier@strozllc.com>
Date: Sat Jul 23 2005 - 00:42:34 CEST
I am attempting to write a class whose string representation changes
Given the following class definition:
class MyClass(object):
def Edit(self):
def View(self):
def setEdit(self):
def setView(self):
...I would expect the following behavior:
In [130]: testObject = MyClass()
Unfortunately, this is what happens instead:
In [130]: testObject = MyClass()
In other words, str() is _NOT_ apparently calling <object>.__str__ as
In [133]: testObject.__str__()
Now, my understanding is that functions/methods are first-order
In [135]: def func1():
However, expressions such as self.__str__ = <some function or method>
Thanks for any responses,
-- Jeffrey E. Forcier Junior Developer, Research and Development Stroz Friedberg, LLC 15 Maiden Lane, 12th Floor New York, NY 10038 [main]212-981-6540 [direct]212-981-6546 http://www.strozllc.com This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No right to confidential or privileged treatment of this message is waived or lost by any error in transmission. If you have received this message in error, please immediately notify the sender by e-mail or by telephone at 212.981.6540, delete the message and all copies from your system and destroy any hard copies. You must not, directly or indirectly, use, disclose, distribute, print or copy any part of this message if you are not the intended recipient.Received on Thu Sep 29 17:06:54 2005 |