fetching class by name
Davide Marchignoli
marchign at science.unitn.it
Wed Feb 7 07:57:40 EST 2001
In comp.lang.python, you wrote:
>
>I think I know the answer to this question before I ask it, but I
>feel like I need to ask anyway.
>
>Is there an easier way to retrieve a class object by name than
>doing a manual lookup through the __dict__ of every module in
>sys.modules?
>
>I think maybe I'm just spoiled by the way objective c gives you a
>cute little utility function to do this for you. Still, looking
>it up manually seems extraordinarily costly.
>
>Thanks,
>--G.
>
maybe eval suits your needs:
>>> class C : pass
...
>>> x = eval('C')
>>> x
<class __main__.C at 80708b0>
Bye,
--
Davide
More information about the Python-list
mailing list