complicated class question
Fred Clift
fclift at verio.net
Fri Nov 8 13:39:33 EST 2002
If any of you could spare a moment of your time and perhaps help me figure
out a problem I'm having, I'd be most grateful. If you dont have time or
dont want to bother with me, then feel free to ignore this email message
:).
My problem has to do with looking for a way to override methods in a
system library that I dont want to modify, that is used in a 3rd party
library that I dont want to modify.
I can summarize the problem with a toy example:
class a:
def foo(self):
print "hi"
class b:
def bar(self):
ainst = a()
ainst.foo()
say that a is defined in a system library and that b is in a 3rd party
library.
I'd like to get b to use a modified version a, without having to change
the code of either
my code would do something like:
binst = b()
<insert your solution here>
binst.bar()
and I'd like the version of a.foo that is called be
def myfoo(self):
print "bye"
Does that make sense?
I could just derive a new class from B and override bar, but in this case,
bar is like 80 lines of code and the the use of the a-classed object is
relatively minimal -- I'd have to basically copy the whole thing -
maintainace problems with new versions of the library etc.
I'm stumped :).
If you've read this far, thanks for your kind interest.
Fred
--
Fred Clift - fred at clift.org -- Remember: If brute
force doesn't work, you're just not using enough.
More information about the Python-list
mailing list