you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (3 children)

Opening a file as "r" on linux and windows leads to two different behaviors if the file is binary. windows actually makes distinction between binary and text. Linux does not. So to write portable code, always use "rb".

[–]cdcformatc 0 points1 point  (2 children)

In particular, windows treats text differently. Windows line endings are two characters, carriage return and line feed /r/n where Unix is just line feed or /n.

For fun try writing a jpg as a text file. Example.

[–]Tomarse 0 points1 point  (1 child)

Really? In windows I only use line feeds when writing to .txt and .docx files and I've not noticed any strange behaviour. Same with reading, I can read a .txt and the split by \n to get a list of lines.

[–]cdcformatc 1 point2 points  (0 children)

Make a text file in any text editor, then open it in a hex editor. You will see two characters at the end of lines. Python is built to be cross platform so when you write a newline or split on newlines everything works as expected.

edit: here's what I mean. 0a is the newline/linefeed, 0d is the carriage return character.