Selecting a different superclass

Chris Rebert clp at
Wed Dec 17 21:33:23 CET 2008

On Wed, Dec 17, 2008 at 6:41 AM, psaffrey at
<psaffrey at> wrote:
> This might be a pure OO question, but I'm doing it in Python so I'll
> ask here.
> The problem is that IDPointSet and MicroArrayPointSet will need to
> inherit from PointSet or TraceablePointSet based on whether I'm
> handling traceable points or not. Can I select a superclass
> conditionally like this in Python? Am I trying to do something really
> evil here?

You're doing something really dynamic; don't think I'd call it
inherently evil though.
All you have to do is use a variable in the inheritance syntax, it's
really quite simple:

superclass = TraceablePointSet if tracing else PointSet

class IDPointSet(superclass):
    #body code here

#use same trick for MicroArrayPointSet


Follow the path of the Iguana...

More information about the Python-list mailing list