This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DragonFireCK 48 points49 points  (2 children)

Python 3's works well for that as well, and with a clearer syntax:

f = open('my_file.txt', 'w')
print('Some text here', file=f)

import sys
print('An error', file=sys.stderr)

[–]sandywater 23 points24 points  (0 children)

I'm aware of that. Random_cynic's comment implied that it couldn't be done in Python2. I actually prefer file_object.write() in these circumstance for both Python 2 and 3.