2

I get the following error. Is there a way to eval import?

>>> eval('import os')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
    import os
         ^
SyntaxError: invalid syntax
3
  • 2
    Use importlib like os = importlib.import_module('os') Commented Aug 30, 2019 at 22:44
  • Use exec, not eval. Commented Aug 30, 2019 at 22:46
  • The same reason you can't write x = import os Commented Aug 30, 2019 at 22:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.