Hans Dushanthakumar wrote: >Thanks for your reply Kent. > >Is it possible to dynamically import a module? > >The foll snippet of code throws an error "ImportError: No module named >testname" > > >t = ["test1.py", "test2.py"] #Actually this list is filled in by a >Tkinter Listbox selection. > >for f in t: > testname = f[:-3] > import "%s"%(testname) > print testname.run_test() > > >Any other means of importing dynamically? > > Well, it's not recommended, but the following will work (I'll leave the lectures on why it's not recommended to the more learned on the list ;-) ):
eval("import %s" % testname) -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor