01quiz QA | submt login

OS Agnostic Newline with Python

0 Points, by ianegan 9d ago
The os.linesep variable provides the appropriate newline character(s) for the operating system your Python code is running on. Using os.linesep allows your file operations to be compatible across different systems without manually adjusting newline characters. Take a look:

  import os
  with open('example_cross_platform.txt', 'w') as file:
      file.write(f"First line{os.linesep}")
      file.write(f"Second line{os.linesep}")
      file.write(f"Third line{os.linesep}")

Answer Count: 0