How do I dynamically import a module in App Engine?

Posted by Scott Ferguson on Stack Overflow See other posts from Stack Overflow or by Scott Ferguson
Published on 2010-12-21T15:16:56Z Indexed on 2010/12/21 15:53 UTC
Read the original article Hit count: 154

Filed under:
|
|
|

I'm trying to dynamically load a class from a specific module (called 'commands') and the code runs totally cool on my local setup running from a local Django server. This bombs out though when I deploy to Google App Engine. I've tried adding the commands module's parent module to the import as well with no avail (on either setup in that case). Here's the code:

mod = __import__('commands.%s' % command, globals(), locals(), [command])
return getattr(mod, command)

App Engine just throws an ImportError whenever it hits this.

And the clarify, it doesn't bomb out on the commands module. If I have a command like 'commands.cat' it can't find 'cat'.

© Stack Overflow or respective owner

Related posts about python

Related posts about django