[Tutor] Returning multiple values from a script

Orri Ganel singingxduck at gmail.com
Thu Jan 12 02:33:19 CET 2006


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.



More information about the Tutor mailing list