[Python-Dev] [PEP] += on return of function call result
Walter Dörwald
walter@livinglogic.de
Thu, 03 Apr 2003 10:53:17 +0200
Greg Ewing wrote:
> Andrew Koenig <ark@research.att.com>:
>
>
>>So the behavior of
>>
>> foo = d.setdefault(r,'')
>> foo += "test %d\n" % t
>>
>>depends on what type foo has, and the OP didn't say.
>
> I assumed that the code snippet was from his actual application, in
> which case he *did* want it to work on strings, in which case, even if
> he had the feature he wanted, it wouldn't have helped him.
> [...]
> Being forced to find another way to update the value in this case is a
> feature, because the absence of such a way when the value is immutable
> makes it clear that there's no way to do what you're trying to do!
Mutable (or at least appendable) strings should probably be done with
StringIO/cStringIO. How about adding support for __iadd__ and
__str__ (and __unicode__) to both?
Bye,
Walter Dörwald