[Tutor] Import and Execute Modules in List

Sean Abrahams Sean Abrahams <sa@sfsu.edu>
Mon Jan 27 16:01:01 2003


I'm developing an application where I want the user to define a list
of modules they want to use and then the application then takes that
list and loads those modules.

As a test, I did this:

------------------------------------
>>> a = ['cgi','Cookie','sys','re']
>>> b = len(a)
>>> for counter in range(b):
...     import a[counter]
  File "<stdin>", line 2
    import a[counter]
            ^
SyntaxError: invalid syntax
------------------------------------

Obviously, this doesn't work, and I don't want to use an if-else
statement.

Thanks,
--Sean