Strange behaviour with os.linesep
Vincent Vande Vyvre
vincent.vandevyvre at swing.be
Tue Jul 23 09:26:07 EDT 2013
Le 23/07/2013 15:10, Vincent Vande Vyvre a écrit :
> The '\n' are in the original file.
>
> I've tested these other versions:
>
> -------------------------------
> def write():
> strings = ['# -*- coding: utf-8 -*-\n',
> 'import os\n',
> 'import sys\n']
> with open('writetest.py', 'w') as outf:
> txt = L_SEP.join([s.rstip() for s in strings]):
> outf.write(txt)
> ------------------------------
>
> -------------------------------
> def write():
> strings = ['# -*- coding: utf-8 -*-',
> 'import os',
> 'import sys']
> with open('writetest.py', 'w') as outf:
> txt = L_SEP.join( strings):
> outf.write(txt)
> ------------------------------
>
> Las, no changes, always correctly displayed in MS bloc-notes but with
> double line in other éditors.
>
Also with:
----------------------------------------
def count():
with open('c:\\Users\\Vincent\\writetest.py', 'r') as inf:
lines = inf.readlines()
for l in lines:
print(l, len(l))
count()
--------------------------------------
The output is:
--------------------------------------
('# -*- coding: utf-8 -*-\r\n', 25)
('import os\r\n', 11)
('import sys', 10)
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
More information about the Python-list
mailing list