Three ways to dynamically load modules in Python
- 2020-04-02 14:24:07
- OfStack
1. Use system function with s/s _()
stringmodule = __import__('string')
2. Use imp module
import imp
stringmodule = imp.load_module('string',*imp.find_module('string'))
3. Use exec
import_string = "import string as stringmodule"
exec import_string