Py2K wishes
Gordon McMillan
gmcm at hypernet.com
Tue Dec 28 17:41:32 EST 1999
Paul Prescod wrote:
[his __fallback__ idea]
> The "fallback" code is presumably very optimized and is of course
> written in Python. It is often the case that I want to have a an
> instance that "falls back" to some other instance. For instance I
> might have an object that almost does what I want but I need to
> wrap some of the methods to be Unicode aware. The other methods
> should just "fall back" automatically. This sort of proxying is
> also useful for working around cycles. Typically we code this by
> hand using __getattr__.
If you're catching specific methods, why not subclass? OTOH,
if your code looks like:
class Proxy:
...
def __getattr__(self, nm):
attr = getattr(self.__obj, nm)
if type(attr) == type(''):
return Unicode(attr)
return attr
then I fail to see how a __fallback__ thingie is going to make
your life any easier.
- Gordon
More information about the Python-list
mailing list