Python sending output to both file and terminal
<p>I was reading this example and its working correctly.</p>

<p>But i am not able to understand how it worked</p>

<pre><code>import sys
class Logger(object):
        def __init__(self, filename="Default.log"):
            self.terminal = sys.stdout
            self.log = open(filename, "a")

        def write(self, message):
            self.terminal.write(message)
            self.log.write(message)

sys.stdout = Logger("log.txt")
print "Hello world !" # this is should be saved in yourlogfilename.txt
</code></pre>

<p>I know that output will be sent to <code>std.stdout</code></p>

<p>Now in the above program we are setting it to Logger object bt how did the write function gets called</p>
