eval to import a module

Use exec:

exec 'import vfs_tests as v'

eval works only on expressions, import is a statement.

exec is a function in Python 3 : exec('import vfs_tests as v')

To import a module using a string you should use importlib module:

import importlib
mod = importlib.import_module('vfs_tests')

In Python 2.6 and earlier use __import__.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)