[BangPypers] How to dynamically load modules in Django/Python

mithun chackravarthy vbnetmithun at gmail.com
Mon Dec 15 07:52:10 CET 2014


Hi ,

I need to load modules dynamically from one of my django app .


   1. lets say 'test' is my app name and am having functions inside it.
   2. in an util function I need to load modules dynamically when a
   function (loader_function) is called with appname and list of functions as
   arguments

      utils.py

      def loader_function(*appname*, *functions*):
             from *'appname'* import *'[list of functions passed]'*
             do SOME stuff
             return stuff

     views.py

     from utils import loader_function
*     stuff =  loader_function('test', ['fun1', 'fun2']*

How can I achieve this.Thanks for your time.

Thanks
Mithu


More information about the BangPypers mailing list