preferred syntax for list extend?
Aahz
aahz at pythoncraft.com
Wed Apr 17 19:26:48 EDT 2002
In article <a9kjh1$qc5$1 at slb1.atl.mindspring.net>,
Andrew Dalke <dalke at dalkescientific.com> wrote:
>
>while += is defined as
>
>list_inplace_concat(PyListObject *self, PyObject *other)
>{
> other = PySequence_Fast(other, "argument to += must be iterable");
> if (!other)
> return NULL;
>
> if (listextend_internal(self, other) < 0)
> return NULL;
>
> Py_INCREF(self);
> return (PyObject *)self;
>}
>
>The code is almost identical, except for that return self part.
>(I don't know why that's needed.)
Heh. That's because of the way __iadd__ works. Immutable objects must
return a new object with __iadd__; mutable objects *MAY* return self
(and usually do).
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
What if there were no rhetorical questions?
More information about the Python-list
mailing list