How to disable assert statements inside a module?
Peter Hansen
peter at engcorp.com
Sun Mar 10 19:50:30 EST 2002
Pearu Peterson wrote:
>
> Is there a way to disable all assert statements inside a module,
> and without calling python with -O switch?
>
> Why? I have developed a module using lots of assert statements (yes,
> they are all relevant). Now when it is finished, I found that
> running python with -O switch the speed up is approximately 4 times. I
> assume that this is due to disabled assert statements. I don't want to
> remove all these assert statements because I might extend this module in
> future when they will be handy again for debugging.
You might look into the Test-Driven Development approach espoused
by Extreme Programming (XP) proponents. Using a proper set of
unit tests is probably going to be a better approach than scattering
asserts throughout your code like that, and you would benefit from
higher performance even without -O, an improved design, and less
need to debug at that level when you extend the module.
Just a thought, but I've never seen code that had so many relevant assert
statements that the program slowed to a quarter normal speed because of
them.
-Peter
More information about the Python-list
mailing list