On Apr 19, 3:12 pm, 7stud <[EMAIL PROTECTED]> wrote:
> On Apr 19, 5:37 am, Steve Holden <[EMAIL PROTECTED]> wrote:
>
>
>
> > It's nothing to do with the name lookup. Alex mentioned that to remind
> > us that the magic "double-under" names are looked up on the type rather
> > than the instance...
>
> P.next()
>
> vs.
>
> type(P).next()
>
> Where is the "double-under" name?

The following example looks up next() in the instance not the class:

class Parrot(object):
    def __init__(self):
        self.next = lambda: "hello"
    def __iter__(self):
        return self
    def next(self):
        yield "goodbye"
        raise StopIteration

p = Parrot()
_t = iter(p)
print _t.next()

-----output: ----
hello

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to