Smart factory class
Arnaud Delobelle
arnodel at googlemail.com
Thu Jan 24 02:25:30 EST 2008
On Jan 24, 7:11 am, kramer31 <kramer.newsrea... at gmail.com> wrote:
> Can anyone tell me if there is a way in python that I can implement a
> factory function which takes as input a string ClassName and returns
> an object of type ClassName?
>>> def mkobj(classname, ns=globals()): return ns[classname]()
...
>>> class A: pass
...
>>> mkobj('A')
<__main__.A instance at 0x6bd28>
>>>
But why do you want to do this?
--
Arnaud
More information about the Python-list
mailing list