cause __init__ to return a different class?

Jonathan Hartley tartley at tartley.com
Thu Sep 15 06:31:16 EDT 2011


Perhaps a more idiomatic way of achieving the same thing is to use a factory function, which returns instances of different classes:

  def PersonFactory(foo):
      if foo:
         return Person()
      else:
         return Child()


Apologies if the code is messed up, I'm posting from Google groups web UI.



More information about the Python-list mailing list