initializing mutable class attributes
Jorge Godoy
godoy at ieee.org
Wed Sep 1 11:14:05 EDT 2004
"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