newbie question - object from a string?

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


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

I have a file named MyHandlers.py 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 gmx.net]
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 peregrine.com> wrote in 
news:mailman.1006800222.5110.python-list at python.org:
[...]
> 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

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list