Re: Optimizing constants in loops

2007-06-13 Thread Michael Hoffman
Thomas Heller wrote: > Just use the builtin __debug__ variable for that purpose. > __debug__ is 'True' if Python is run normally, and 'False' > if run with the '-O' or '-OO' command line flag. > The optimizer works in the way you describe above (which > it will not if you use a custom variable).

Re: Optimizing constants in loops

2007-06-13 Thread Thomas Heller
Michael Hoffman schrieb: > The peephole optimizer now takes things like > > if 0: > do_stuff() > > and optimizes them away, and optimizes away the conditional in "if 1:". > > What if I had a function like this? > > def func(debug=False): > for index in xrange(100): > if de

Optimizing constants in loops

2007-06-13 Thread Michael Hoffman
The peephole optimizer now takes things like if 0: do_stuff() and optimizes them away, and optimizes away the conditional in "if 1:". What if I had a function like this? def func(debug=False): for index in xrange(100): if debug: print index do_stuff(i