Accessing parent objects
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Mar 24 19:54:56 EDT 2018
On Sat, 24 Mar 2018 13:31:13 -0700, Rick Johnson wrote:
> On Saturday, March 24, 2018 at 1:20:24 PM UTC-5, D'Arcy Cain wrote:
[...]
>> I tried various forms of super() but that didn't seem to work.
Define "doesn't see to work".
> Python's super (at least <= 2.x) is notoriously blinkered. I avoid it
> like the plague. And i'd advise you to do the same.
There's nothing wrong with super() in Python 2. You just have to
understand what you're doing. It's still the right solution for doing
inheritance the right way.
(Of course it doesn't exist in Python 1, so if Rick is still using Python
1.5, that's a good excuse not to use super().)
The trick is to use new-style classes that inherit from object, and avoid
the old-style classes that don't:
# Good
class Spam(object):
...
# Not so good
class Spam:
...
> PS: I am pleased to see you old fellers are finally warming up to the
> wonderful OOP paradigm, but i gotta say, what is most entertaining to me
> is watching you seasoned pros struggle with the simplist OOP concepts.
Ah yes, simple concepts like being unable to get super() working in
Python 2. Good one Rick.
--
Steve
More information about the Python-list
mailing list