How do I write a line to a file in modern Python? I heard that this is deprecated:
print >>f, "hi there"
Also, does "\n"
work on all platforms, or should I use "\r\n"
on Windows?
file-iopython
How do I write a line to a file in modern Python? I heard that this is deprecated:
print >>f, "hi there"
Also, does "\n"
work on all platforms, or should I use "\r\n"
on Windows?
Best Answer
This should be as simple as:
From The Documentation:
Some useful reading:
with
statementopen()
'a'
is for append, or use'w'
to write with truncationos
(particularlyos.linesep
)