C-style static variables in Python?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Apr 3 08:17:37 CEST 2010


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



More information about the Python-list mailing list