<div dir="ltr">Top of my head:<br>Open the file for binary reading at the start: <font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;">file(&#39;project_release.a&#39;, &#39;rb&#39;).</span></font><br>
Later, open a file (not necessarily the same one) for writing: <font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;">file(&#39;project_release2.a&#39;, &#39;wb&#39;)</span></font><br>
<br>Cheers,<br>Imri<br><br><div class="gmail_quote">On Sun, Dec 27, 2009 at 3:41 PM, Yitzhak Wiener <span dir="ltr">&lt;<a href="mailto:Yitzhak.Wiener@dspg.com">Yitzhak.Wiener@dspg.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">









<div link="blue" vlink="purple" lang="EN-US">

<div>

<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Hi Dear People,</span></font></p>

<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>

<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">As really beginner in Python, I tried to write a simple
script that opens a binary file and replace all appearance of some data with
another data.</span></font></p>

<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">It doesn’t show me any error message, but file is not
modified. Can you help to understand why?</span></font></p>

<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>

<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">My script is as follows:</span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;">from array import array</span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;">a = array(&#39;H&#39;)</span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;">f =  file(&#39;project_release.a&#39;)</span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;">a.fromfile( f,100 )</span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;"> </span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;"># update the content</span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;">for i in a:</span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;">   if i == 0xFFFF:</span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;">       a[ a.index(i) ] = 0x7777</span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;"> </span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;"> </span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font color="blue" face="Arial" size="2"><span style="font-size: 11pt; font-family: Arial; color: blue;">#update to new file</span></font></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">a.tofile(f)</span></font></p>

<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>

<p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size: 12pt;"> </span></font></p>

<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Thanks,</span></font></p>

<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Yitzhak</span></font></p>

<p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size: 12pt;"> </span></font></p>

</div>

<br>
______________________________________________________________________<br>
DSP Group, Inc. automatically scans all emails and attachments using MessageLabs Email Security System.<br>
_____________________________________________________________________<br>
</div>


<br>_______________________________________________<br>
Python-il mailing list<br>
<a href="mailto:Python-il@hamakor.org.il">Python-il@hamakor.org.il</a><br>
<a href="http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il" target="_blank">http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Imri Goldberg<br>--------------------------------------<br><a href="http://plnnr.com/">http://plnnr.com/</a> - automatic trip planning<br><a href="http://www.algorithm.co.il/blogs/">http://www.algorithm.co.il/blogs/</a><br>
--------------------------------------<br>-- insert signature here ----<br>
</div>