initializing mutable class attributes

Dan Perl dperl at rogers.com
Wed Sep 1 12:01:30 EDT 2004


My mistake.  You're right, and it's all because of the inheritance from
'object', which probably defines a default, empty, __init__.  I haven't made
a habit of subclassing from 'object' yet and I see that I'll have to do
that.  Thanks.

Dan

"Jorge Godoy" <godoy at ieee.org> wrote in message
news:m3n00aggxu.fsf at g2ctech.com...
> "Dan Perl" <dperl at rogers.com> writes:
>
> > Not in Python.  A user of my library has to invoke the parent's class
> > __init__ in their own __init__.  What happens if, in a future release, I
get
> > rid of the __init__ in the parent class?  Or the other way around.  An
early
> > release does not have a parent __init__, the users don't invoke it
because
> > they can't, and then, in a future release, I add the parent __init__
because
> > I added some attributes.  It breaks all the users' code.  This is poor
> > encapsulation.
>
>
> I'm getting in the middle of the discussion so forgive-me if this example
> doesn't apply here.
>
>
> >>> class test(object):
> ...     def test(self):
> ...             print "Just a test"
> ...
> >>> class derived(test):
> ...     def __init__(self):
> ...             test.__init__(self)
> ...     def showit(self):
> ...             self.test()
> ...
> >>> d = derived()
> >>> d.showit()
> Just a test
> >>>
>
> There was no "__init__" explicitly defined in 'test'.
>
>
> Be seeing you,
> -- 
> Godoy.     <godoy at ieee.org>





More information about the Python-list mailing list