Is Python suitable for some binary file editing?

Hung Jung Lu hungjunglu at
Wed Dec 5 11:43:29 EST 2001

David Rollo <drollo at> wrote in message news:<1FD639F0.1DA46084 at>...
> I am considering as a beginning Python project an iterative task
> involving conversion of a set of image files to an alternative format.
> The file conversion is simply making the same change to a handful of
> characters at a particular offset, and saving under a new filename. It
> would be repeated several thousand times, looping through a hierarchical
> directory structure in Windows, editing and renaming as it went.

Yeah, I did this sort of things for thousands of multimedia binary
files like .bmp, .wav, etc. I can't think of any other language better
than Python in this. I was doing it in Java at beginning, but found
out Python was far better. Python is kind of slow, but developer's
time was much more important to me than the execution time. Also,
because it's simple file processing, it was easy to "parallel
process": I often used several machines to do gigantic batches of

For file/directory operations, you maybe interested in os.stat(),
os.system(), etc. In fact, take a look at the os module under "Files
and Directories." Look also the os.path module, it allows you to walk
directories and tweak file/directory path names. Regular expressions
(the re module) and string methods help, too. In multimedia
processing, you often have some third-party utilities or your own C++
binary tools, in that case, the os.system() really helps. When you get
a lot of fun done, start to implement some user interface by using
things like wxPython. And later you can start to look at socket or
xmlrpc programming to allow "parallel processing", or make things into
binary executable by using things like py2exe, or set up Zope server
to do the job remotely. It's a lot of fun! :)

Hung Jung

More information about the Python-list mailing list