Write to a binary file

  • Thread starter Thomi Aurel RUAG A
  • Start date
T

Thomi Aurel RUAG A

Hy
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. 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". The write behaviour on line feed's isn't really
usefull 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.

Thank you for any help
Aurel
 
K

kyosohma

Hy
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. 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". The write behaviour on line feed's isn't really
usefull 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.

Thank you for any help
Aurel

I don't know if these will help or not, but they all have info on
binary file writing:

http://mail.python.org/pipermail/python-list/2001-September/105529.html
http://docs.python.org/tut/node9.html
http://www-128.ibm.com/developerworks/opensource/library/os-python8/

If your data is a bunch of strings, have to tried just concatenating
them into one variable and writing that? If Python is the only program
you will use to read the data, you should be able to pickle it.

Mike
 
G

Grant Edwards

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().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top