View Full Version : Python Question
CheeseWarfare
30th May 2004, 03:33 PM
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
30th May 2004, 04:50 PM
I don't know. Have you checked the documentation (http://www.python.org/doc/)?
wolveso
30th May 2004, 05:35 PM
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
30th May 2004, 07:42 PM
Thank you that worked perfectly! :-D
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.