maybe using python's importlib

Werner

···

On 7/21/2015 19:54, Boštjan Mejak wrote:

def tryToImport(module):

    try:
        import module

    except ImportError:
        print("The import failed.")

As you can see from my code above, the function tryToImport() takes a 'module' argument which is then taken as a module to be imported. But I always get "The import failed." message. Why does my code not work? No module can be imported this way, even the built-in Python modules. How can I refactor my code to make this work?