Will open() function change line-endings in files?

Assuming that you have CRLF endings in your file, the logic is:

  • When reading, you will get a string with just LF.
  • When you write that string back into the file, LF will be converted to CRLF again.

That should be fine for CSV. In general, this behavior is nice whenever working with plain text files. What you get is a string ready for processing that is independent of the platform, since all line endings are LF. After you modified the contents, when you write the file, it has line endings typical of your platform.

For images, you definitely want binary mode. For one thing, binary data will most often not be decodable as UTF-8. For another, if it happens to contain a sequence of bytes that means LF, that will stay LF when you read it, and if you write it back, it will become CRLF, making the file unreadable.

The meaning you assign to “corrupt” is not entirely clear to me. I hope this answers your question. Please see details at Built-in Functions — Python 3.9.1 documentation.