From 140b3b699cc15a4cde7af04348ff7e7a86ce945b Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Thu, 17 May 2012 12:29:30 -0400 Subject: [PATCH] * Added wpylib.interactive_tools.printstr class to facilitate logging of print-ed output in interactive python sessions. --- interactive_tools.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/interactive_tools.py b/interactive_tools.py index a7b6cd4..f25c104 100644 --- a/interactive_tools.py +++ b/interactive_tools.py @@ -155,3 +155,21 @@ def init_interactive(use_readline=True, global_ns=None): return True #print "_-helo" + + +class printstr: + """A hack to record printout in a logged interactive python session + (I had logged ipython in mind, but other similar framework can use + this as well). + We intentionally use __repr__ to print the string. + + Usage: + printstr() + """ + def __init__(self, obj): + self.str = str(obj) + def __str__(self): + return self.str + def __repr__(self): + return self.str +