# set displayhook
from pprint import pprint
+ try:
+ from subprocess import Popen, PIPE
+ except ImportError:
+ use_subprocess = False
+ else:
+ use_subprocess = True
+ pager = os.environ.get("PAGER") or 'more'
def displayhook(value):
if value is not None:
__builtin__._ = value
- pprint(value)
+ if use_subprocess:
+ _pipe = Popen(pager, shell=True, stdin=PIPE)
+ pipe = _pipe.stdin
+ else:
+ pipe = os.popen(pager, 'w')
+ pprint(value, stream=pipe)
+ pipe.close()
+ if use_subprocess:
+ _pipe.wait()
sys.displayhook = displayhook
return "Usage: pager('filename')"
def __call__(self, filename):
- pager = os.environ.get("PAGER") or 'more'
os.system("%s '%s'" % (pager, filename.replace("'", '"\'"')))
__builtin__.pager = _Pager()