Last active
February 15, 2018 10:16
-
-
Save pavan538/7d86b92fd20be8e76506e9203e987952 to your computer and use it in GitHub Desktop.
import python modules dynamically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The built-in __import__ function accomplishes the same goal as using the import statement, | |
but it's an actual function, and it takes a string as an argument. | |
""" | |
sys = __import__('sys') | |
os = __import__('os') | |
re = __import__('re') | |
unittest = __import__('unittest') | |
moduleNames = ['sys', 'os', 're', 'unittest'] | |
modules = map(__import__, moduleNames) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment