PATCH: Augmented assignment
Rainer Deyke
root at rainerdeyke.com
Fri Jun 9 18:39:29 EDT 2000
Warren B. Focke <moron at Glue.umd.edu> wrote in message
news:8hrdkn$3uf at stochastic.eng.umd.edu...
> But it does. Accessing an attribute of an object or an item in a
> container type can invoke arbitrary code, with arbitrarily freakish
> side effects. Evaluating x[17] might suck up hours of CPU time and
> gibibytes of RAM, redefine builtin functions, launch the missiles, or
> annoy your mother. Having all of these things happen once, as in
> x[17] += 1, is much preferable to, and potentially significantly
> different from, having them happen twice, as in x[17] = x[17] + 1.
> It's not just syntactic sugar that
What if x is a database that loads an object from file on __getitem__ and
writes it on __setitem__? Then x[17] += 1 would work correctly only if
x[17] has no += operation defined and the interpreter falls back on
executing x[17] = x[17] + 1.
--
Rainer Deyke (root at rainerdeyke.com)
Shareware action/role-playing games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list