The input() function calls eval() on the value you give it. Eval() can evaluate any _expression_. That's generally insecure and not recommended - people could type in anything, as you're trying to do :-)
But anyway, that is why 'import ...' directly doesn't work, import is a statement, not an expression. However, you can use the built-in function __import__(), that imports the module and returns it. That loads it into memory, but it doesn't add the module to the current namespace. What do you need this for? Remco Gerlich On Nov 15, 2007 4:25 PM, Mihai Iacob <[EMAIL PROTECTED]> wrote: > 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: > > >>> input() > import time > > Traceback (most recent call last): > File "<pyshell#168>", line 1, in <module> > input() > File "<string>", line 1 > import time > ^ > SyntaxError: invalid syntax > >>> > > > Is there another way in which i can import modules > with the input() command? > > > > > > > ____________________________________________________________________________________ > Never miss a thing. Make Yahoo your home page. > http://www.yahoo.com/r/hs > _______________________________________________ > Tutor maillist - [email protected] > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
