So i have the current code:
module = input('What module?: ')
print(module.run())
& the goal is that it’ll do the run() function of a pre-made module, which module in question is being chosen by the user.
>Solution :
You can use the importlib module to dynamically import the module based on the user’s selection, and then execute the run() method of that module, presuming the module files are in the same directory as the script.
import importlib
module_name = input('Enter module name: ')
try:
module = importlib.import_module(module_name)
module.run()
except ModuleNotFoundError:
print(f"Module {module_name} not found")
except AttributeError:
print(f"Module {module_name} does not have a run() function")