"Aliasing" an object's __str__ to a different method
Jeffrey E. Forcier
jforcier at strozllc.com
Sat Jul 23 10:59:56 EDT 2005
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-style classes is that I only
read up on them very recently, and was attempting to get myself into
the habit of inheriting from 'object' by default. Go figure.
Anyway, to take a step back, the *actual* actual reason for my
investigation into this issue is that I'm attempting to create a
collection of classes representing HTML page/form elements, many of
which are represented differently depending on whether they're in a
"view" or "edit" state.
And ideally I wanted to be able to hold a collection of these objects
and toggle them all to one state or the other, then bandy them about
as if they were strings, e.g. mixing them with literal strings via str
(obj).
Clearly there are at least a handful of ways to accomplish this, but
the one that came to mind first was, as I said at the beginning, to
define both behaviors on each object and then have the ability to
point __str__ to one or the other. I suppose now I need to figure out
which is more important, that ease-of-use of overriding __str__ or
whatever benefits new-style classes give (something I'm still a bit
unclear on).
Thanks again,
Jeff
--
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.
More information about the Python-list
mailing list