Re: Instantiate an object based on a variable name

2009-12-31 Thread Steven D'Aprano
On Thu, 31 Dec 2009 08:54:57 -0800, Wells wrote: > Sorry, this is totally basic, but my Google-fu is failing: > > I have a variable foo. I want to instantiate a class based on its value- > how can I do this? The right way to do it is like this: >>> class C: ... pass ... >>> foo = C # assi

Re: Instantiate an object based on a variable name

2009-12-31 Thread Diez B. Roggisch
Wells schrieb: Sorry, this is totally basic, but my Google-fu is failing: I have a variable foo. I want to instantiate a class based on its value- how can I do this? class Foo(object): pass ze_class = Foo f = ze_class() Diez -- http://mail.python.org/mailman/listinfo/python-list

Re: Instantiate an object based on a variable name

2009-12-31 Thread Stephen Hansen
On Thu, Dec 31, 2009 at 8:54 AM, Wells wrote: > Sorry, this is totally basic, but my Google-fu is failing: > > I have a variable foo. I want to instantiate a class based on its > value- how can I do this? It sort of depends on where these classes are. If they're in the current namespace/module,

Re: Instantiate an object based on a variable name

2009-12-31 Thread Martin P. Hellwig
Wells wrote: Sorry, this is totally basic, but my Google-fu is failing: I have a variable foo. I want to instantiate a class based on its value- how can I do this? My crystal ball is failing too, could you please elaborate on what exactly you want to do, some pseudo code with the intended res

Instantiate an object based on a variable name

2009-12-31 Thread Wells
Sorry, this is totally basic, but my Google-fu is failing: I have a variable foo. I want to instantiate a class based on its value- how can I do this? -- http://mail.python.org/mailman/listinfo/python-list