Python 2.7 : How to constrain the delimiter of a new line to be '\n' on Windows? -
i seek write file in python 2.7 on windows.
but new line delimiter seems '\r\n'
, delimited '\n'
.
tried utilize open
newline='\n'
raised exception.
tried:
>>> 'something\n'.rstrip('\r\n') >>> 'something'
which didn't work well.
the next works me , writes using \n
instead of \r\n
import io f= io.open("myfile.txt", "w", newline="\n") #note io module requires write unicode f.write(unicode("asdasd\nasdasasd\n")) f.close()
python windows python-2.7
No comments:
Post a Comment