<div dir="ltr"><div class="gmail_default" style="color:rgb(0,0,0)"><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 23, 2013 at 7:42 AM, Vincent Vande Vyvre <span dir="ltr"><<a href="mailto:vincent.vandevyvre@swing.be" target="_blank">vincent.vandevyvre@swing.be</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">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.<br>

<br>
Example with this code:<br>
------------------------------<u></u>----------------<br>
# -*- coding: utf-8 -*-<br>
<br>
import os<br>
L_SEP = os.linesep<br>
<br>
def write():<br>
    strings = ['# -*- coding: utf-8 -*-\n',<br>
                'import os\n',<br>
                'import sys\n']<br>
    with open('writetest.py', 'w') as outf:<br>
        for s in strings:<br>
            outf.write(s.replace('\n', L_SEP))<br></blockquote><div><br></div><div style="color:rgb(0,0,0)" class="gmail_default">I must ask why you are setting strings with a newline line ending only to replace them later with os.linesep.  This seems convoluted compared to doing something like</div>
<div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">def write():</div><div style="color:rgb(0,0,0)" class="gmail_default">    strings = ['#-*- coding: utf-8 -*-', 'import os', 'import sys']</div>
<div style="color:rgb(0,0,0)" class="gmail_default">    with open('writetest.py', 'w') as outf:</div><div style="color:rgb(0,0,0)" class="gmail_default">        for s in strings:</div><div style="color:rgb(0,0,0)" class="gmail_default">
            outf.write(s)</div><div style="color:rgb(0,0,0)" class="gmail_default">            outf.write(L_SEP)</div><div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">
Or something equivalent.</div><div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">If, however, the source strings come from a file you've created somewhere (and are loaded by reading in that file line by line), then I can see a problem.  DOS line endings are carriage returns ('\r\n'), whereas standard UNIX files use just newlines ('\n').  Therefore, if you are using the code:</div>
<div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">s.replace('\n', L_SEP)</div><div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">
in Windows, using a Windows-generated file, then what you are likely doing is converting the string sequence '\r\n' into '\r\r\n', which is not what you want to do.  I can imagine some text editors interpreting that as two endlines (since there are 2 \r's).  Indeed, when I execute the code:</div>
<div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div class="gmail_default"><div class="gmail_default"><span style="color:rgb(0,0,0)">>>> l = open('test.txt', 'w')</span><br></div><div class="gmail_default">
<font color="#000000">>>> l.write('This is the first line\r\r\n')</font></div><div class="gmail_default"><font color="#000000">>>> l.write('This is the second\r\r\n')</font></div><div class="gmail_default">
<font color="#000000">>>> l.close()</font></div><div class="gmail_default"><br></div><div style="color:rgb(0,0,0)">on UNIX and open the resulting file in gedit, it is double-spaced, but if I just dump it to the screen using 'cat', it is single-spaced.</div>
<div style="color:rgb(0,0,0)"><br></div><div style="color:rgb(0,0,0)">If you want to make your code a bit more cross-platform, you should strip out all types of end line characters from the strings before you write them.  So something like this:</div>
<div style="color:rgb(0,0,0)"><br></div><div style="color:rgb(0,0,0)">with open('writetest.py', 'w') as outf:</div><div style="color:rgb(0,0,0)">    for s in strings:</div><div style="color:rgb(0,0,0)">        outf.write(s.rstrip('\r\n'))</div>
<div style="color:rgb(0,0,0)">        outf.write(L_SEP)</div><div style="color:rgb(0,0,0)"><br></div><div style="color:rgb(0,0,0)">Hope this helps,<br>Jason</div></div></div>
</div></div>