[Pythonmac-SIG] Binary writes to text files?

Chris chriss@dnastar.com
Fri, 14 Apr 2000 17:27:01 -0500


Policy question:
				
What sould we do when binary data is written to a file open in text mode?

e.g.:

				f = open("xyzzy", "w")

				f.write( 0x0007820A )

Currently MacPython will happily write out 0x000782 thru a text file,
but will then convert 0x0A -> 0x0D, presumably garbling the data.

Perhaps we should be raising an execption on encountering and unresonably
strange contol-char like 0x00 or 0x07.

				f.write( 0x0007820A ) -> traceback ... exc Binary Write to Text file.

This might break some code from UNIXland but it's likely to break itself
anyway,
as soon as it writes any byte that contains 0x0A, so it seams to me that
any explicit
error is better than (possibly  subtile) data curruption. This problem is
even worse
on Windows, since the 0x0A -> 0x0A0D conversion dosn't even leave the
data with
the right length, we Mac- & Win- -Python should raise the same exception.
Idealy,
we might want to raise the exception on unix as well, the same way that
Mac- & Win-
object to case mismatch in module names.