View Full Version : Python Question
CheeseWarfare
2004-05-30, 08:33 AM CDT
Is there a way you can have the user input something and have the module import a module with the name of the input.
:confused:
Hope that makes sense. Any help appreciated. :(
Jman
2004-05-30, 09:50 AM CDT
I don't know. Have you checked the documentation (http://www.python.org/doc/)?
wolveso
2004-05-30, 10:35 AM CDT
Interesting question.. got me fiddling anyways : )
newmodule = raw_input("Module to load: ")
mymodule = __import__ (newmodule)
So, for example, if the user inputted "sys" to load the sys module, you'd use..
print mymodule.version
..instead of..
print sys.version
CheeseWarfare
2004-05-30, 12:42 PM CDT
Thank you that worked perfectly! :-D
vBulletin® v3.8.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.