473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Write to a binary file

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
Apr 4 '07 #1
2 3518
On Apr 4, 11:40 am, "Thomi Aurel RUAG A" <Aurel.Th...@ruag.comwrote:
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/pyt...er/105529.html
http://docs.python.org/tut/node9.html
http://www-128.ibm.com/developerwork...ry/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

Apr 4 '07 #2
On 2007-04-04, Thomi Aurel RUAG A <Au*********@ruag.comwrote:
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!!
Apr 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: kee | last post by:
Hi All, I am trying to write binary data to a file, which is bmp image: Open "d:\temp\test001.bmp" For Binary Access Write As #1 Put #1, 1, strImage Close #1 *** strImage contains binary...
4
by: Jon Hyland | last post by:
Hi all, I'm looking for the fastest way to write (and/or read) binary to a file in VC++. I've been using the fstream object in this way: //unsigned char *pDataOut and long iLength initilized...
1
by: sleepylight | last post by:
I'm running into a strange problem with ostreams's write function. Please see the code below: ofstream save((job->b->get_filename()).c_str(), ios::out | ios::binary); if (!save) { cout <<...
5
by: philip | last post by:
Here is some lines of code than I wrote. You can copy/paste theis code as code of form1 in a new project. My problem is this one : I try to write in a file a serie of bytes. BUT some bytes...
3
by: Billy Smith | last post by:
I'm trying to write a little utility that will write some binary data to a file via a javascript and Windows Script Host under Windows XP. The only way to do this that I can find is to convert...
6
by: ericunfuk | last post by:
Hi ALL, I want to read a binary file(it's pic.tif file, I guess it's binary file?), then write it to a new file), I have several questions about this process: When I use fread() to read a...
13
by: zach | last post by:
Can someone help me out, I can't figure out what I'm doing wrong to write to a file in binary mode. What's wrong with my code? <?php $fileName = "something.dat"; $string = "This is a...
6
by: aagarwal8 | last post by:
Hi, I am trying to write the contents of a textbox to a file in binary format. My code looks like this... private void btnWriteToFile_Click(object sender, EventArgs e) { FileStream fs =...
1
by: =?Utf-8?B?U3RldmVU?= | last post by:
I have a structure that contains both 32x32 and 16x16 icons plus some text. I want to write all this to an XML file so that I can recover the icons later in an application. Can someone tell me how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.