conditional running of code portion

Serhiy Storchaka storchaka at gmail.com
Sun Aug 5 12:40:40 EDT 2012


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)





More information about the Python-list mailing list