How to implement factory patterns or other solutions more elegantly

The

scenario is that
has a stack of py files in the commands directory. Each file is a class. Each class has a different approach.

such as

-sharp daemon.py 
import commands

while True:
    message = json.loads(mq.receive())
    if not hasattr(commands, message["class"])
        logger.warn("error")
    command = commands[message["class"]]()
    command. message["action"] (message) ????

how should it be implemented or I shouldn"t use python? in this way Are you used to using php?

May.09,2021

answer your own questions.

module = __import__('module.%s' % modulename)
class_ = module()
func = getattr(class_, 'func')
func()
Menu