What is the semantics meaning of 'object'?

Roy Smith roy at panix.com
Sun Jun 23 12:49:42 EDT 2013


In article <51c723b4$0$29999$c3e8da3$5496439d at news.astraweb.com>,
 Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:

> On Sun, 23 Jun 2013 10:15:38 -0600, Ian Kelly wrote:
> 
> > If you're worried about efficiency, you can also explicitly name the
> > superclass in order to call the method directly, like:
> > 
> >         A.__init__(self, arg)
> 
> Please don't. This is false economy. The time you save will be trivial, 
> the overhead of inheritance is not going to be the bottleneck in your 
> code, and by ignoring super, you only accomplish one thing:
> 
> - if you use your class in multiple inheritance, it will be buggy.

One thing I've never understood about Python 2.x's multiple inheritance 
(mostly because I almost never use it) is how you do something like this:

class Base1(object):
   def __init__(self, foo):
      self.foo = foo

class Base2(object):
   def __init__(self, bar):
      self.bar = bar

class Derived(Base1, Base2):
   def __init__(self, foo, bar):
      # now what???

I need to call __init__() in both of my base classes.  I don't see how 
super() can do that for me.  I assume I would just do:

   def __init__(self, foo, bar):
      Base1.__init__(self, foo)
      Base2.__init__(self, bar)

am I missing something here?

For what it's worth, I never bother to inherit from object unless I know 
there's something I need from new style classes.  Undoubtedly, this 
creates a disturbance in The Force, but such is life.



More information about the Python-list mailing list