changing __getattr__ dynamically

Dan Bentley dtbentley at gmail.com
Wed Jul 28 04:45:50 EDT 2004


class foo(object):
  def __getattr__(self, name):
    return 42

def e(self, name):
  return 2.7

bar = foo()
print bar.baz
bar.__getattr__ = e
print bar.baz

I'd expect this to print:
42
2.7

But instead it prints:
42
42

Is there a way to change the actual __getattr__ used at runtime?

-D"python 2.3.3 on Mac OS X 10.3.4"an



More information about the Python-list mailing list