<div class="gmail_extra"><div class="gmail_quote">On 10 November 2012 08:34, Carl Smith <span dir="ltr"><<a href="mailto:carl.input@gmail.com" target="_blank">carl.input@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div id=":15c">Can you not redirect stdout to a method with something like...<br>
<br>
class StandardOut(object):<br>
<br>
def __init__(self): pass<br>
<br>
def write(self, string):<br>
do_stuff()<br>
<br>
I'm not sure if that'll work. Just thinking out loud really.</div></blockquote></div><br>I don't think this (overriding sys.stdout) will work for what Gökhan is trying to do. Unlike displayhook(), which gets an object, sys.stdout.write() only gets the string form, so you can't easily produce a different representation.<br>
<br>For a Python class, you could monkeypatch __str__() to produce your preferred representation, but ndarray is defined in compiled code, so that's not an option.<br><br>Thomas<br></div>