C-style static variables in Python?
Ethan Furman
ethan at stoneleaf.us
Sat Apr 3 02:44:32 EDT 2010
Steven D'Aprano wrote:
> 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.
Happy to do so -- if I made a mistake I'd like to know about it and learn.
It'll have to wait two days 'til I get back to work, though... I'll post
it asap.
~Ethan~
More information about the Python-list
mailing list