argument checking before getattr

Jason Orendorff jason at jorendorff.com
Sun Jan 13 11:28:39 EST 2002


> I guess __getattr__ would apply the function object
> internally. Would it?

No.  If you write code like
  print object.attribute
then Python does, basically,
  print getattr(object, 'attribute')

If you write:
  object.method(args)
then Python does, basically:
  m = getattr(object, 'method')
  m(args)

When you override __getattr__, it only changes
the getattr behavior.  __getattr__ does not call
the method.  The method still gets called
as usual, with the arguments you provide.

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list