AW: Write to a binary file

Thomi Aurel RUAG A Aurel.Thomi at ruag.com
Thu Apr 5 01:40:22 EDT 2007


Hy Mike
Thanks for your links, unfortunately they weren't very usefull for my
specific problem.

Hy Grant Edwards
Thanks for your hints.
A simplified test programm to compare the function for opening a file i
used ("file()") and your suggested "os.open()" showed different
behaviour.

My simple testprogramm:

--- START ---
import os

msg = chr(0x02) + chr(0x36) + chr(0x00) + chr(0x01) + chr(0x0a) +
chr(0xb0) + chr(0x77)

f = os.open('/dev/pytest', os.O_RDWR)
os.write(f,msg)
os.close(f)

f = file('/dev/pytest', 'wb')
f.write(msg)
f.close()
--- END ---

The "pytest" device is a very simple device-driver which prints out
(using "printk()") the buffer delivered to the write function in a
hexadecimal format ("Pytest write> [buffer in hex format]").

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 ---

Using os.open will work for me, i wasn't aware of the existence of
several file interaces.

Thanks for your help
regards

Aurel



More information about the Python-list mailing list