Useful decorator

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Apr 14 22:51:22 EDT 2007


On Sat, 14 Apr 2007 15:03:00 -0700, Paul Rubin wrote:

> Then to chop bazillion_items to 20 items, I just write:
> 
>     @truncate(20)
>     def generate_bazillion_items():
>        for line in bazillion_line_file:
>           yield itemify(line)
> 
> When I want to run the whole file, I comment out the @truncate line,
> and if I want to debug again, I just uncomment it.


By All-Father Wodan's one good eye! Why not do something like this?

if __debug__:
   generate_bazillion_items = truncate(20)(generate_bazillion_items)

Now you don't have to comment/uncomment dozens of lines all over your
application, but only set a single global.



-- 
Steven.




More information about the Python-list mailing list