I\'m used to doing print >>f, \"hi there\"
However, it seems that print >>
is getting deprecated. What is the recommended way t
When I need to write new lines a lot, I define a lambda that uses a print
function:
out = open(file_name, 'w')
fwl = lambda *x, **y: print(*x, **y, file=out) # FileWriteLine
fwl('Hi')
This approach has the benefit that it can utilize all the features that are available with the print
function.
Update: As is mentioned by Georgy in the comment section, it is possible to improve this idea further with the partial
function:
from functools import partial
fwl = partial(print, file=out)
IMHO, this is a more functional and less cryptic approach.