How to avoid "f.close" (no parens) bug?
Richard Brodie
R.Brodie at rl.ac.uk
Wed Feb 11 11:18:18 EST 2004
RE: How to avoid "f.close" (no parens) bug?>#- class Test:
>#- def __getattr__(self, name):
>#- print "Nobody expects the %s!" % name
>#-
>#- t = Test()
>#- t.spanish_inquisition
>And why is this useful?
>In other words, what happen if the interpreter does not let you do "t.spanish_inquisition"?
If you can't retrofit a 'getattr' method on an attribute in this way, you are likely
to specify get methods in your stable APIs to start with. Then you'll have code that
looks more like Java: A.getB().getC().getD() instead of A.B.C.D
More information about the Python-list
mailing list