[Python-il] problem in script

Imri Goldberg lorgandon at gmail.com
Sun Dec 27 16:26:00 IST 2009


Top of my head:
Open the file for binary reading at the start: file('project_release.a',
'rb').
Later, open a file (not necessarily the same one) for writing:
file('project_release2.a',
'wb')

Cheers,
Imri

On Sun, Dec 27, 2009 at 3:41 PM, Yitzhak Wiener <Yitzhak.Wiener at dspg.com>wrote:

>  Hi Dear People,
>
>
>
> 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.
>
> It doesn’t show me any error message, but file is not modified. Can you
> help to understand why?
>
>
>
> My script is as follows:
>
> from array import array
>
> a = array('H')
>
> f =  file('project_release.a')
>
> a.fromfile( f,100 )
>
>
>
> # update the content
>
> for i in a:
>
>    if i == 0xFFFF:
>
>        a[ a.index(i) ] = 0x7777
>
>
>
>
>
> #update to new file
>
> a.tofile(f)
>
>
>
>
>
> Thanks,
>
> Yitzhak
>
>
>
> ______________________________________________________________________
> DSP Group, Inc. automatically scans all emails and attachments using
> MessageLabs Email Security System.
> _____________________________________________________________________
>
> _______________________________________________
> Python-il mailing list
> Python-il at hamakor.org.il
> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
>
>


-- 
Imri Goldberg
--------------------------------------
http://plnnr.com/ - automatic trip planning
http://www.algorithm.co.il/blogs/
--------------------------------------
-- insert signature here ----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://hamakor.org.il/pipermail/python-il/attachments/20091227/60c302ba/attachment.htm 


More information about the Python-il mailing list