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

Terry Reedy tjreedy at home.com
Sun Sep 23 10:39:14 CEST 2001


"> 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.

Terry J. Reedy





More information about the Python-list mailing list