Optimize flag question

Steve Holden steve at holdenweb.com
Sat Feb 25 01:56:51 EST 2006


Olivier Langlois wrote:
> Hi,
> 
>  
> 
> This is my first post on the list. I played with the –O flag option and 
> I found the hard way that it was breaking the scripts I am using because 
> they rely on the assert statement that the optimize flag remove. From 
> there, I tried to find more information on the effect that this flag has 
> on scripts but I have not found much…
> 
>  
> 
> So my question is: what are the ‘optimizations’ that the Python 
> interpreter is doing when you specify the optimize flag and is there 
> anything I should be cautious about when using it?
> 
It's not wise to write your program to rely on an assertion error being 
raised, or an assert statement having a side effect, since (as you have 
discovered) when you request optimization the assert statements are 
effectively removed from your program.

Could you outline the code that needs to be in to make the program work, 
so we can assess the errors for ourselves?

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list