all Python 3osterm
os.linesep
constants
The line terminator on this system: '\n' on Unix and macOS, '\r\n' on Windows.
Syntax
os.linesep # '\n' на Unix, '\r\n' на Windows
Text files do not need os.linesep and are even harmed by it: a file in text mode translates '\n' to the platform line ending itself, so writing os.linesep on Windows produces '\r\r\n'. Write '\n'. os.linesep is useful when working with bytes or in binary mode.
Examples
import os
print(repr(os.linesep)) # → ? '\n' на Unix, '\r\n' на Windows
with open('t.txt', 'w', encoding='utf-8') as f:
f.write('a\nb\n') # в текстовом режиме пишут '\n' — перевод сделает файл
with open('t.txt', encoding='utf-8') as f:
print(f.read().splitlines()) # → ['a', 'b']
See also
Open in the full glossarydocs.python.orgReport an inaccuracy