Exception as the primary error handling mechanism?

r0g aioe.org at technicalbloke.com
Tue Jan 5 15:48:46 CET 2010


Steven D'Aprano wrote:
> On Tue, 05 Jan 2010 13:06:20 +0000, r0g wrote:
<snip>
>> Well maybe I didn't quite get it then, could you explain a bit further?
>>
>> My understanding was that asserts aren't executed at all if python is
>> started with the -O or -OO option, 
> 
> Correct.
> 
> 
>> or run through an optimizer. 
> 
> I don't know what you mean by that.


I've never used them but I heard there are optimizers for python
(psycho?). I assumed these would do everythin -O does and more,
including losing the asserts.



> 
>> If
>> that's the case how can you expect it to validate anything at all in
>> production? 
> 
> The asserts still operate so long as you don't use the -O switch.
> 
>> Do you mean for debugging in situ or something? Could you
>> maybe give me an example scenario to illustrate your point?
> 
> 
> There are at least two sorts of validation that you will generally need 
> to perform: validating user data, and validating your program logic.
> 
<snipped very detailed and clear response, thanks :)>


Cool, that's what I thought i.e. you can't rely on asserts being there
so don't use them for anything critical but it's still a good idea to
use them for logic/consistency checking in production code as, should
you be running your production code unoptimised, it might catch
something you'd otherwise miss.

Thanks for responding is such detail :)

Roger.



More information about the Python-list mailing list