Subclassing complex with computed arguments
danperl at rogers.com
Fri Nov 26 06:33:06 CET 2004
I need a clarification. Does "sample" have to be an instance of complex or
can it be a subclass of complex? So can it be an instance of point as long
as point is a subclass of complex?
If "sample" has to be an instance of complex and not of a subclass, I think
you need to subclass point from complex and override the __new__() method to
return an instance of complex and override __init__() to use all your
arglist. In that case you also need yet another method to actually create
instances of point.
If "sample" can be an instance of a subclass of complex, I think you can
just subclass point from complex and override only __init__().
There is more in the details I guess, but I would like to first see an
answer to the above questions.
"Peter Olsen" <pcolsen at comcast.net> wrote in message
news:a86143fb.0411251430.50665acf at posting.google.com...
>I want to define a class "point" as a subclass of complex.
> When I create an instance
> sample = point(<arglist>)
> I want "sample" to "be" a complex number, but with its real and
> imaginary parts computed in point()'s __init__ function with their
> values based on the arglist. I want to compute with point instances
> as though they were native complex numbers, but I want to be able to
> define some new methods and over-ride some of complex's existing ones.
> This is probably very simple, but it hasn't been simple to me.
> Please feel free to flame me with RTFM as long as you also tell me
> where in TFM to R.
> If you respond, please send a copy directly to me. I seldom have
> access to this group. (My primary network isn't connected to the
More information about the Python-list