title: how to print directly to a text file in both python 2.x and 3.x?
body: <p>Instead of using <code>write()</code>, what are the other way to write to a text file in Python 2 and 3?</p>
  
  <pre><code>file = open('filename.txt', 'w')
  file.write('some text')
  </code></pre>