Augmented Assignement (was: Re: PEP scepticism)

Paul Prescod paulp at ActiveState.com
Tue Jul 3 20:11:05 CEST 2001


Alex Martelli wrote:
> 
>...
> 
> Relying on writing this as "totImportant + countOf[key]" rather than
> "countOf[key] + totImportant" seems to me far more fragile than
> relying on +=.  And if I ever have this in a python -i and when
> interactively exploring I write countOf[this}+countOf[that] I
> definitely do NOT want this to mess up my further explorations -- I
> shudder at the thought.

Okay, I can see that this solution is fragile.

>...
> But while I can conceive Python growing an ismutable() builtin,

Really? Wouldn't you say that the concept is very slippery? For instance
in this context, we only care about things that are sequence-mutable. A
sequence that was attribute-mutable would probably be considered
immutable. So now we need an issequencemutable() builtin..but we don't
have a good definition of a sequence...

> I'd hardly imagine an isadvanced() builtin.  While not fully
> pinned down, "mutable" is still a fundamental concept in a way
> that "advanced" isn't...

I don't want to make a big deal of the terminology. How do you know
whether a class you use is going to overload getitem? getattr? +? You
have to read the documentation for the class. There is no rule that
"mutable objects will overload getitem", you just make the decision on a
case-by-case basis based on your problem domain.
-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list