user225312
user225312

Reputation: 131627

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?

Upvotes: 2

Views: 607

Answers (2)

RolfBly
RolfBly

Reputation: 3862

A non-issue is something you don't have to pay any attention to for the rest of your life. That's not the case here, it's all too easy to mess up line-endings in Python, even.

For platform-independent writing, see here

For p-i reading, see here

Upvotes: 1

Rafe Kettler
Rafe Kettler

Reputation: 76955

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

Upvotes: 3

Related Questions