How to Dynamically Load Modules or Classes in Python
Python provides a feature to create and store classes and methods and store them for further use. The file containing these sets of methods and classes is called a module
. A module can have other modules inside it.
For more information, refer to Python Modules
A simple example of importing a module is shown below in which, there are 2 files that are module.py and importing_mod.py in the same directory. The module.py file acts as a module to import_mod.py file.
"Hi ! % s Welcome to GfG"
module as mod
Hi! User_1 Welcome to GfG
Dynamically Loading Modules or Classes
The modules added in the above code are importing modules statically i.e in compile time. In Python we can import modules dynamically by two ways
Share your thoughts in the comments
Please Login to comment...