Tino Dai wrote:

I just remember that there was a performance hit or something for doing
that.
Does that sound familiar to anyone?

Yes, and no.

Creating a try block in Python is lightweight and fast. It is about as fast as the "pass" statement, that is, pretty damn fast and more or less faster than doing *anything* at all. But technically, yes, there is overhead to try.

(This is in contrast to Java, where just creating a try block is expensive.)

But *catching* the exception is expensive. Not hugely expensive, it isn't like it takes a second or two, but it does take maybe ten microseconds[1] or so. If you're doing a LOT of exception-catching, all those microseconds can add up.

But for the use-case you're talking about, who cares if your program takes an extra ten microseconds, or even a millisecond? You're never going to notice.





[1] Number plucked out of thin air.


--
Steven

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to