Strange behaviour with os.linesep

Vincent Vande Vyvre vincent.vandevyvre at
Tue Jul 23 13:42:13 CEST 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('', 'w') as outf:
         for s in strings:
             outf.write(s.replace('\n', L_SEP))


The syntax `s.replace('\n', L_SEP)`is required for portability.

Vincent V.V

More information about the Python-list mailing list