Is there a way to instantiate a subclass from a class constructor?

Paul Rubin phr-n2001 at
Sun Sep 23 10:43:39 CEST 2001

"Terry Reedy" <tjreedy at> writes:
> "> The obvious workaround is to define a function that calls the
> appropriate
> > constructor, e.g.
> >   def newpoly(sides):
> >     if sides==3: return Triangle(...)
> >     ...
> A factory function like this is a standard solution that has been
> discussed in several posts on this list.  Don't knock it.

I'm not knocking it, I just don't see how to extend the class from
additional base classes without having to add more special code to
the factory function, which is against the OO spirit.  Any thoughts?

More information about the Python-list mailing list