Python Forum

Full Version: selecting a module at run time
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i am working on some new scripts to handle openvpn tunnels. there will be commands to start and stop particular ends of a tunnel in listen/server mode or connect/client mode. i want to have the configuration of a whole tunnel (both ends) in a single python modules. all of these modules will be in a particular directory. i could then write commands to do things with groups of tunnels or with all tunnels such as "tun-cmd server all start".
Maybe importlib can help you.

import importlib

my_module = 'os'
m = importlib.import_module(my_module)

print(m.getenv("PATH"))