On Fri, 2009-01-09 at 10:46 -0800, Dennis Lee Bieber wrote: > On Wed, 07 Jan 2009 11:38:29 -0500, "J. Cliff Dyer" <j...@unc.edu> > declaimed the following in comp.lang.python: > > > I want to be able to create an object of a certain subclass, depending > > on the argument given to the class constructor. > > > > I have three fields, and one might need to be a StringField, one an > > IntegerField, and the last a ListField. But I'd like my class to > > delegate to the proper subclass automatically, so I can just do: > > > > >>> f1 = Field('abc') > > >>> f2 = Field('123') > > >>> f3 = Field('D,E,F') > > And how do you differentiate a string that contains a comma from a > purported list? > > What is expected for: > > ambiguous = Field('He said "Blast, it won''t work"')
My strings don't look like that. Nor is that relevant to my question. I created a simple, uncluttered example to illustrate my issue with instantiating the proper subclass for a given argument. I did not try to make sure my example handled all edge cases properly. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list