AW: Write to a binary file
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Thu Apr 5 13:27:19 EDT 2007
En Thu, 05 Apr 2007 11:38:06 -0300, Grant Edwards <grante at visi.com>
escribió:
> On 2007-04-05, Thomi Aurel RUAG A <Aurel.Thomi at ruag.com> wrote:
>
>> The output was:
>> --- Start ---
>> Pytest write> 02 36 00 01 0a b0 77
>> Pytest write> 02 36 00 01 0a
>> Pytest write> b0 77
>> --- END ---
>
> I'm surprised that the normal file object's write method does
> that -- especially for a "binary" file. IMO, it's a bug when a
> binary file object treats 0x0a differently than other byte
> values.
A write() call on a Python file object gets directly translated into a
fwrite() C runtime library call. Any special handling is made inside that
library.
> But, using the file object to read/write a device is
> probably not a good idea because of undefined behavior like
> that. File objects also do their own buffering, which I
> suspect isn't what you want.
I agree - using os.open, os.write etc. appears to be the right thing here.
--
Gabriel Genellina
More information about the Python-list
mailing list