replacing substrings within strings

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Feb 14 08:51:40 EST 2007


Diez B. Roggisch:
> That's the price to pay for immutable strings.

Right, but CPython has array.array("c") too. Using Diez Roggisch's
code:

>>> from array import array
>>> arrs = array("c", "010203040506")
>>> arrs[:2], arrs[4:5] = arrs[4:6], arrs[:2]
>>> arrs.tostring()
'0302013040506'

Using such arrays is useful if you have to do lot of processing before
the final tostring().

Bye,
bearophile




More information about the Python-list mailing list