
Le 24 déc. 2016 8:42 PM, "Neil Girdhar" <mistersheik@gmail.com> a écrit :
Usually, when an exception is hit that will (probably) crash the program, no one cares about less than a microsecond of performance.
Just one example. By design, hasattr(obj, name) raises an exception to return False. So it has the cost of building the exception + raise exc + catch it. Victor

On Mon, Dec 26, 2016 at 8:51 AM, Victor Stinner <victor.stinner@gmail.com> wrote:
Le 24 déc. 2016 8:42 PM, "Neil Girdhar" <mistersheik@gmail.com> a écrit :
Usually, when an exception is hit that will (probably) crash the program, no one cares about less than a microsecond of performance.
Just one example. By design, hasattr(obj, name) raises an exception to return False.
So it has the cost of building the exception + raise exc + catch it.
Printing an exception to the console can afford to be expensive, though. So if the work can be pushed into __str__, it won't hurt anything that try/excepts around it. ChrisA
participants (2)
-
Chris Angelico
-
Victor Stinner