Strange behaviour with os.linesep
Vincent Vande Vyvre
vincent.vandevyvre at swing.be
Tue Jul 23 07:42:13 EDT 2013
On Windows a script where de endline are the system line sep, the files
are open with a double line in Eric4, Notepad++ or Gedit but they are
correctly displayed in the MS Bloc-Notes.
Example with this code:
----------------------------------------------
# -*- coding: utf-8 -*-
import os
L_SEP = os.linesep
def write():
strings = ['# -*- coding: utf-8 -*-\n',
'import os\n',
'import sys\n']
with open('writetest.py', 'w') as outf:
for s in strings:
outf.write(s.replace('\n', L_SEP))
write()
----------------------------------------------
The syntax `s.replace('\n', L_SEP)`is required for portability.
Regards
-
Vincent V.V
More information about the Python-list
mailing list