Search code examples
pythonfile-ioline-endings

Line endings and reading and writing to text files


I am writing a small script that will need to read and write to text files on Windows and Linux and perhaps Mac even. The script will be used by users on all perhaps all of these platforms (Windows for sure) and interchangeably - so a user who wrote to a file X on Windows, may read the file on Linux with the script.

What precautions should I take or how should I implement my code that it is able to handle line endings across various platforms? (reading and writing)

Or this is a non-issue and Python handles everything?


Solution

  • It's a non-issue, Python is smart like that. It handles line endings across platforms very well.