Variable arguments (*args, **kwargs): seeking elegance

John Ladasky john_ladasky at sbcglobal.net
Mon Oct 7 12:26:51 EDT 2013


Thanks, everyone, for your replies.  Perhaps I have complicated things unnecessarily?  I was just trying to do some error-checking on the arguments supplied to the class constructor.  Perhaps Python already implements automatically what I am trying to accomplish manually?  I'll tinker around with some minimal code, try to provoke some errors, and see what I get.

Here is one more detail which may be relevant.  The base class for the family of classes I am developing is a numpy.ndarray.  The numpy.ndarray is a C extension type (and if I understand correctly, that means it is immutable by ordinary Python methods).  Subclassing ndarray can get a bit complicated (see http://docs.scipy.org/doc/numpy/user/basics.subclassing.html).  The ndarray.__init__ method is inaccessible, instead one overrides ndarray.__new__.

Making further subclasses of a subclassed numpy.ndarray, each of which may have their own arguments, is what I am trying to accomplish while adhering to the "DRY" principle.



More information about the Python-list mailing list