S
Steven Bethard
So when I'm writing a class and I define an __init__ method, I sometimes
haven't called object.__init__, e.g.:
class C(object):
def __init__(self, x):
self.x = x
instead of
class C(object):
def __init__(self, x):
super(C, self).__init__()
self.x = x
Looking at:
http://www.python.org/2.2.3/descrintro.html#__new__
"The built-in type 'object' has a dummy __new__ and a dummy __init__"
seems to suggest that the super call here is unnecessary. It's also not
made in the Super class example from that document:
http://www.python.org/2.2.3/descrintro.html#superexample
I'm trying to get in the habit of calling super in all __init__ methods,
but it seems like it's unnecessary when the only superclass is object.
Assuming that the base class of C doesn't get changed from object, are
there consequences of not making this call?
Steve
haven't called object.__init__, e.g.:
class C(object):
def __init__(self, x):
self.x = x
instead of
class C(object):
def __init__(self, x):
super(C, self).__init__()
self.x = x
Looking at:
http://www.python.org/2.2.3/descrintro.html#__new__
"The built-in type 'object' has a dummy __new__ and a dummy __init__"
seems to suggest that the super call here is unnecessary. It's also not
made in the Super class example from that document:
http://www.python.org/2.2.3/descrintro.html#superexample
I'm trying to get in the habit of calling super in all __init__ methods,
but it seems like it's unnecessary when the only superclass is object.
Assuming that the base class of C doesn't get changed from object, are
there consequences of not making this call?
Steve