Why does Output to file not work but print statement does?
<p>I have the following code:</p>

<pre><code>for node, value in sorted(d.iteritems()):
    outfile.write([node] + value)
    print(node, value)
</code></pre>

<p>I read a few different SO posts about this and am still somewhat confused. The print statement works perfectly, printing the key and value correctly in the interpreter. But I couldn't figure out a way to get the outfile.write() statement to work here. Would greatly appreciate any clarification!</p>
