Alan Gauld wrote:
"James Thornton" <ja...@jamesthornton.com> wrote
I found this issue -- I was setting setting self.s to the return value
of super() and trying to use self.s in params():
...but this won't work.
No, because super returns whatever the superclass
method returns. Which in init() is usually None.
No, super returns a proxy object that encapsulates knowledge of the
superclasses of the argument (usually "self", but not necessarily).
>>> class A(object):
... attr = "Nobody expects the SPANISH INQUISITION!"
...
>>> class B(A):
... attr = "something else"
...
>>> b = B()
>>> s = super(B, b)
>>> s
<super: <class 'B'>, <B object>>
What you do with that proxy object is then lookup attributes (usually
methods, but data attributes are fine too):
>>> s.attr
'Nobody expects the SPANISH INQUISITION!'
If you look up a method, and *call* that method, then of course the
complete chain of super::method lookup::method call will return whatever
the method itself returns. But that's different from saying that super
itself returns (say) None.
--
Steven
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor