Skip to content

Instantly share code, notes, and snippets.

@miohtama
Created April 24, 2012 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miohtama/2479234 to your computer and use it in GitHub Desktop.
Save miohtama/2479234 to your computer and use it in GitHub Desktop.
Wrap Python print statement to breakpoint when something prints by catching output
import sys
old_f = sys.stdout
BAD_OUTPUT = "hospitalArrival_dateTimeStrokeOnSet"
class F:
def write(self, x):
if x == BAD_OUTPUT:
import pdb ; pdb.set_trace()
old_f.write(x)
def writelines(self, lines):
old_f.writelines(lines)
def flush(self):
old_f.flush()
sys.stdout = F()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment