Write to a binary file

Grant Edwards grante at visi.com
Wed Apr 4 13:48:58 EDT 2007


On 2007-04-04, Thomi Aurel RUAG A <Aurel.Thomi at ruag.com> wrote:

> I'm using Python 2.4.2 on an ARM (PXA-270) platform (linux-2.6.17).
> My Goal is to write a list of bytes down to a file (opened in binary
> mode) in one cycle. The crux is that a '0x0a' (line feed) will break the
> cycle of one writing into several pieces.

Says who?  I've never experienced this...

> Writing to a "simple" file, this wouldn't cause any problem.
>
> Assuming - without questioning ;-) - that a device file (/dev/*) has to
> be written in one cycle because one write call will be interpreted as
> one "transaction".

I've never seen a write() on a file descriptor broken up by
Python.  What makes you think this is an issue?

> The write behaviour on line feed's isn't really usefull

What write behavior?

> because such "transactions" would be broken up into serveral
> pieces and therefore for the device into several
> "transactions".
>
> Is there a possibility to write a list of bytes "en bloc" to a
> binary file? (without the interpreting of the line feed's)
> Opening a file i binary mode (i.e "wb") seems not to be
> enough.

It sounds like you're using open() and Python file objects.
You probably ought to use os.open() an os.write().

-- 
Grant Edwards                   grante             Yow!  I want DUSTIN
                                  at               HOFFMAN!! ... I want
                               visi.com            LIBRACE!! YOW!!



More information about the Python-list mailing list