Unable to restore stdout to original (only to terminal)
<p>I need to output all my print statements to both terminal and file.
I've found a solution in <a href="http://stackoverflow.com/questions/616645/how-do-i-duplicate-sys-stdout-to-a-log-file-in-python">this stackoverflow question</a>
So i use </p>

<pre><code>class Tee(object): 
    def __init__(self, name): 
        self.file = open(name, "a") 
        self.stdout = sys.stdout 
        sys.stdout = self 
    def __del__(self): 
        sys.stdout = self.stdout 
        self.file.close() 
    def write(self, data): 
       self.file.write(data) 
       self.stdout.write(data)

sys.stdout = Tee("log.txt")
</code></pre>

<p>That's works great , </p>

<p>My problem is when i want to stop writing to file and go back to normal operation that's print only to terminal<br>
I tried to use del(sys.stdout) to invoke the <strong>del</strong> method with no luck.<br>
i even tried to change the last line to:</p>

<pre><code>    multiple_print = Tee("log.txt")
    sys.stdout = multiple_print
</code></pre>

<p>and than use del(multiple_print) and failed</p>

<p>No matter what i tried , further uses of <em>print</em> still written to terminal and file both.</p>

<p>Any ideas?</p>
