Mihai Iacob wrote:
The input function takes a character string and attempts to interpret it as a Python _expression_. import is a statement, not an _expression_.Hello, I was wondering if there is a way to import modules using the input() command. If i try to do it directly it gives me an error: Yes: modname = raw_input() exec "import " + modname That can be a security risk, in that a use could enter "time; import os; os.rmdir('some_valuable_directory')" You could prescan modname for semicolons to reduce the risk. Safer is: modname = raw_input() globals()[modname] = __import__(modname) |
_______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
