Various hints
Assorted tips and tricks for advanced developers
Replace strings in many files simultaneously
For example to replace the Copyright statement in all py files of the current and all subdirectories (the "**/*py" pattern only works in zsh terminals):
perl -pi -w -e 's/ 2004-2005 / 2004-2006 /g;' **/*py
"(" or similar special characters need to be escaped with "\", for example:
perl -pi -w -e 's/\(C\) 2004-2005 /\(C\) 2004-2006 /g;' **/*py
Profiling python code
example:
import profile profile.run( 'myMethod()', 'report.out' ) ## Analyzing import pstats p = pstats.Stats('report.out') ## long steps and methods calling them p.sort_stats('cumulative').print_stats(20) p.print_callers(0.1) ## time consuming methods p.sort_stats('time').print_stats(10)