Python Language __import__() function


Example

The __import__() function can be used to import modules where the name is only known at runtime

if user_input == "os":
    os = __import__("os")

# equivalent to import os

This function can also be used to specify the file path to a module

mod = __import__(r"C:/path/to/file/anywhere/on/computer/module.py")