title: How to redirect the output of print to a TXT file
body: <p>I have searched Google, Stack Overflow and my Python users guide and have not found a simple, workable answer for the question.</p>
  
  <p>I created a file c:\goat.txt on a Windows 7 x64 machine and am attempting to print "test" to the file. I have tried the following based on examples provided on StackOverflow:</p>
  
  <p>At this point I don't want to use the log module since I don't understand from the documentation of to create a simple log based upon a binary condition.  Print is simple however how to redirect the output is not obvious.</p>
  
  <p>A simple, clear example that I can enter into my interperter is the most helpful.</p>
  
  <p>Also, any suggestions for informational sites are appreciated (NOT pydocs).</p>
  
  <pre><code>import sys
  print('test', file=open('C:\\goat.txt', 'w')) #fails
  print(arg, file=open('fname', 'w')) # above based upon this
  print&gt;&gt;destination, arg
  
  print&gt;&gt; C:\\goat.txt, "test" # Fails based upon the above
  </code></pre>