Mutable Strings - Any libraries that offer this?

Scott David Daniels Scott.Daniels at Acm.Org
Tue Jul 21 10:03:29 EDT 2009


Steven D'Aprano wrote:
> On Mon, 20 Jul 2009 21:08:22 +1000, Ben Finney wrote:
>> What is it you're trying to do that makes you search for a mutable
>> string type? It's likely that a better approach can be found.
> 
> When dealing with very large strings, it is wasteful to have to duplicate 
> the entire string just to mutate a single character.
> 
> However, when dealing with very large strings, it's arguably better to 
> use the rope data structure instead.

The general problem is that whether strings are mutable or not is an
early language design decision, and few languages provide both.
Mutable strings need lots of data copying to be safe passing args to
unknown functions; immutable strings need lots of copying for ncremental
changes.  The rope is a great idea for some cases.

I'd argue Python works better with immutable strings, because Python is
too slow at per-character operations to be running up and down strings
a character at a time, changing here and there.  So it becomes more
natural to deal with strings as chunks to pass around, and it is nice
not to have to copy the strings when doing that passing around.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list