Promoting Python
Marko Rauhamaa
marko at pacujo.net
Wed Apr 6 15:59:41 EDT 2016
Ian Kelly <ian.g.kelly at gmail.com>:
> On Wed, Apr 6, 2016 at 1:22 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> Why is a SimpleNamespace object not an iterator even though it
>> provides __iter__ and __next__?
>
> Because Python expects those methods to be defined in the class dict,
> not the instance dict.
The documentation does state:
these are used to allow user-defined classes to support iteration
although the rest of it only refers to objects.
It seems to me CPython is being a bit too picky here. Why should it care
if the method is a class method or an object method?
Anyway, that leaves the clever iterator trick out of No-Buzzword Python.
Marko
More information about the Python-list
mailing list