What is the pythonic way to write strings to file?

Viewed 1678

What's the difference between using File.write() and print>>File,?

Which is the pythonic way to write to file?

>>> with open('out.txt','w') as fout:
...     fout.write('foo bar')
... 

>>> with open('out.txt', 'w') as fout:
...     print>>fout, 'foo bar'
... 

Is there an advantage when using print>>File, ?

2 Answers
Related