Is Python dangerous for dealing with binary files? -
i read on python tutorial: (http://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files)
python on windows makes distinction between text , binary files; end-of-line characters in text files automatically altered when data read or written. behind-the-scenes modification file data fine ascii text files, it’ll corrupt binary data in jpeg or exe files. careful use binary mode when reading , writing such files.
i don't quite understand how 'end-of-line characters in text files altered' 'corrupt binary data'. because feel binary data don't have such things end-of-line.
can explain more of paragraph me? it's making me feel python doesn't welcome binary files.
you have take care open files on windows binary (open(filename, "rb")
) , not text files. after there no problem using data.
particularly end-of-line on windows '\r\n'
. , if read binary file text file , write out, single '\n'
transformed in '\r\n'
sequences. if open files binary (for reading , writing) there no such problem.
python capable of dealing binary data, , have take kind of care in language on windows systems, not in python (but developers of python friendly enough warn of possible os problems). in systems linux end-of-line single character distinction exists well, less cause problem when reading/writing binary data text (i.e. without b
option opening of files).
Comments
Post a Comment