newbie question - object from a string?

Gordon Scott gordon.scott at
Tue Nov 27 18:14:11 CET 2001

Thanks for the reply.  Didn't get this until this morning.

I have a file named in which I have the class MyHandler.

when I use

__import__('MyHandlers', globals(), locals(), ['MyHandler'])  or
eval('MyHandler()', globals(), locals())  or eval('MyHandlers.MyHandler()',
globals(), locals())

I get a NameError: name 'MyHandler' is not defined.

-----Original Message-----
From: Chris Liechti [mailto:cliechti at]
Sent: Monday, November 26, 2001 12:50 PM
To: Gordon Scott
Subject: Re: newbie question - object from a string?

[posted and mailed]

Gordon Scott <gordon.scott at> wrote in 
news:mailman.1006800222.5110.python-list at
> Is there a way to dynamically import the class? Or is there entirely
> different approach I should be 
> using to accomplish this?

try the builtin function "__import__" (not the keyword)


Chris <cliechti at>

More information about the Python-list mailing list