views:

23

answers:

2

I'm confused on how to do this, I'm passing in a dictionary with different values, such as "app" which is the name of the app (so that I can better decouple code for easier modularization).. so this is just a simplified example and its not working so I'm wondering how to use the variable "app" within the string that is calling the models import.. thanks for any advice

infodict={'app':'myappname'}
app = infodict['app']
from web1.app.models import modelname
+1  A: 

You probably need something like importlib (Python 2.7). If you version of Python doesn't have importlib then you can use plain old __import__.

For example:

import sys
module_name = "web1.%s.models" % app
__import__(module_name)
models = sys.modules[module_name]
models.modelname
Manoj Govindan
+1  A: 

you should use contenttypes

Mermoz