clarification on open file modes

tubby tubby at bandaheart.com
Thu Jan 4 21:46:32 EST 2007


Does a py script written to open and read binary files on Windows affect 
files on a Linux or Mac machine in a negative way? My concern is 
portability and safety. I want scripts written within Windows to work 
equally well on Linux and Mac computers.

Is this the safest, most portable way to open files on any platform:

fp = open(file_name, 'rb')
fp.close()

I understand that doing the following on Windows to a binary file (a 
jpeg or exe files for example) can cause file corruption, is that correct?

fp = open(file_name, 'r')
fp.close()

How can a simple open in read mode corrupt data???



More information about the Python-list mailing list