Python profiling using line_profiler - clever way to remove @profile statements on-the-fly?
I want to use the excellent line_profiler , but only some of the time. To make it work I add @profile before every function call, e.g. @profile def myFunc(args): blah return and execute kernprof.py -l -v mycode.py args But I don't want to have to put the @profile decorators in by hand each time, because most of the time I want to execute the code without them, and I get an exception if I try to include them, e.g. mycode.py args Is there a happy medium where I can dynamically have the decorators removed based on some condition switch/argument, without having to do things manually and/or modify