"bob gailer" <[EMAIL PROTECTED]> wrote
> 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')"
Even more risky is the fact that modules can contain executable
code that is run when t
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 expr
Mihai Iacob 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
The input function takes a character string and attempts to
Mihai Iacob 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 "", line 1, in
> input()
> File "", line 1
>
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 "", line 1, in
input()
File "", line 1
import time
^
SyntaxError: invalid s