[Python-Dev] [PEP] += on return of function call result
Andrew Koenig
ark@research.att.com
02 Apr 2003 09:54:35 -0500
Luke> example code:
Luke> log = {}
Luke> for t in range(5):
Luke> for r in range(10):
Luke> log.setdefault(r, '') += "test %d\n" % t
Luke> pprint(log)
Luke> instead, as the above is not possible, the following must be used:
Luke> from operator import add
Luke> ...
Luke> ...
Luke> ...
Luke> add(log.setdefault(r, ''), "test %d\n" % t)
Luke> ... ARGH! just checked - NOPE! add doesn't work.
Luke> and there's no function "radd" or "__radd__" in the
Luke> operator module.
Why can't you do this?
for t in range(5):
for r in range(10):
foo = log.setdefault(r,'')
foo += "test %d\n" % t
--
Andrew Koenig, ark@research.att.com, http://www.research.att.com/info/ark