import modules at runtime

Michal Wallace (sabren) sabren at manifestation.com
Mon May 8 23:46:56 CEST 2000


On Mon, 8 May 2000 martin_valiente at my-deja.com wrote:

> Hi *
> 
> Is there a way to create an  object instance giving its classname at
> runtime?

Hey Martin,

how's this? :)

    >>> class C:
    ...    pass
    ...
    >>> def makeNew(className):
    ...     return getitem(globals(),className)()
    ...
    >>> makeNew('C')
    <__main__.C instance at 80dac50>


Cheers,

- Michal
-------------------------------------------------------------------------
http://www.manifestation.com/         http://www.linkwatcher.com/metalog/
-------------------------------------------------------------------------





More information about the Python-list mailing list