On Mon, 20 Jul 2009 21:08:22 +1000, Ben Finney wrote: > casebash <walkr...@gmail.com> writes: > >> I have searched this list and found out that Python doesn't have a >> mutable string class (it had an inefficient one, but this was removed >> in 3.0). Are there any libraries outside the core that offer this? > > A mutable string would not (AFAICT) be usefully implementable as a > subclass of the built-in string types. So even if such a type existed, > it would not be useable with all the functionality that works with > strings.
If applications ignore duck-typing and do isinstance(value, str), it's arguably the application and not the value that is broken. Besides, with the new __isinstance__ method, surely such a mutable string could claim to be an instance of string without needing to inherit from string? > 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. http://en.wikipedia.org/wiki/Rope_(computer_science) -- Steven -- http://mail.python.org/mailman/listinfo/python-list