How to modify a string in place?

John Powers jpowers at acm.org
Fri May 14 12:16:12 EDT 1999


I have read a large binary image of a program into a Python string and need
to patch hundreds of places in the string to reflect relocated addresses.
Since strings are immutable, I wind up cutting the string apart (beforehole
= image[:hole]; afterhole = image[hole+4:]) then reconstructing the image
(image = beforehole + reloc + afterhole). This is extremely slow!

I would like to modify the string in place. Any ideas?






More information about the Python-list mailing list