initializing mutable class attributes

Shalabh Chaturvedi shalabh at cafepy.com
Thu Sep 2 20:36:25 EDT 2004


Dan Perl wrote:

> I will be a good Pythoneer/Pythonista and I will invoke parent __init__'s
> whenever using a library.  My concern was not as a library user, but as a
> library developer.  In which case I don't like the idea of relying on users
> to be good Python coders.

Don't worry about that - just send them to c.l.py and here we'll badger 
them till they succumb and promise to call their parent __init__s 
properly <wink>.

Seriously though, I think it's part of Python ideology to trust the 
programmer a little more. Notice no private or protected members. 
Keeping things explicit and not implicit such as in this case trains 
users very quickly. They'll remember to call the parent __init__, or 
figure out very quickly when it doesn't work (hopefully with useful 
error messages). If things were happening behind the scenes, users will 
have a hard time finding out what's going on when it does not work as 
expected. Or if they are power users and want to tweak something, 
they'll may have to burrow around quite a bit.

That said, in cases it may actually be useful to do certain things 
automatically. After all, making life easier for the user is certainly a 
good thing. IMO, it's important to accomodate needs of all kinds of 
users, but not their fancies. From what I've seen, that seems to be the 
way Python itself is developed.

Just my $0.02.

Cheers,
Shalabh




More information about the Python-list mailing list