Serhiy Storchaka <storch...@gmail.com> writes: > On 05.08.12 09:30, Steven D'Aprano wrote: >> If you are working in a tight loop, you can do this: >> >> if VERBOSE_FLAG: >> for item in loop: >> print(DEBUG_INFORMATION) >> do_actual_work(item) >> else: >> for item in loop: >> do_actual_work(item) > > Or this: > > if VERBOSE_FLAG: > def do_work(item): > print(DEBUG_INFORMATION) > do_actual_work(item) > else: > do_work = do_actual_work > > for item in loop: > do_work(item)
Be warned: a function call is *much* more expensive than an "if variable:". -- http://mail.python.org/mailman/listinfo/python-list