On Fri, 02 Apr 2010 19:48:59 -0700, Ethan Furman wrote: >> The heuristic I use is, if I expect the try block to raise an exception >> more than about one time in ten, I change to an explicit test. In this >> case, since the exception should only be raised once, and then never >> again, I would use a try...except block. > > That was my reasoning as well, but when I timed it for one million runs > (so 1 instantiation, 999,999 simple calls), the __getattr__ time was .5 > seconds, the try...execpt block was .6; at ten million it was 5 and 6.
Care to share your timing code? Not that I don't trust your results, but timings are very sensitive to the exact thing you do, and I'd like to see what that is. -- Steven -- http://mail.python.org/mailman/listinfo/python-list