Naive idiom questions
Grant Edwards
grante at visi.com
Thu Jan 31 16:48:53 EST 2008
On 2008-01-31, Terran Melconian <te_rem_ra_ove_an_forspam at consistent.org> wrote:
> * Why are there no real mutable strings available?
[...]
> I want to be able to accumulate a string with +=, not by going
> through an intermediate list and then doing ''.join(),
So what's stopping you?
>>> s = "one"
>>> s += " two"
>>> s
'one two'
>>>
> because I think the latter is ugly.
Then don't do it. :)
> There are also times when I'd like to use the string as a
> modifiable buffer.
That would be an array of characters or bytes:
http://docs.python.org/lib/module-array.html
> Is the python idiom that this is actually the Right Thing for
> reasons I'm not seeing?
I'm not sure what you're asking. AFAIK, the main reason that
strings are immutable is so they can be used as dict keys.
> Is there a fundamental reason it would be hard to
> implement a mutable string in cpython?
What problem would a mutable string solve that an array of
chars won't?
> * What's the best way to initialize a list of lists?
Hmm. I guess I never need to do that.
> * Is there a way to get headings in docstrings?
Docstrings? Real Men Don't Write Docstrings!
--
Grant Edwards grante Yow! Now, let's SEND OUT
at for QUICHE!!
visi.com
More information about the Python-list
mailing list