Python Language Importing modules __import__() function

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


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/")

Got any Python Language Question?