Possible Duplicate:
Dynamic module import in Python
I need a functionality that allows users to import multiple modules from the command line. So first let's set up the code that allows users to pass as many arguments as they want into a list:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("cmd", action="store", nargs='*')
args = parser.parse_args()
args_list = args.cmd
I know you can import as many modules as you want using this syntax:
import sys, os, math
So now I just need to find a way to unstring each element from that list(args_list
) of strings with module names so I can do the following:
for el in args_list:
import unstring(el)