I have the below code. Is this an ok way to do this? I'm wanting to make the dictionary a bit smaller by doing something more like if exec(f"self.{script}"): and only store the script name with the function reference, but that doesn't seem to work and just provides a none. I think I would be ok with this current solution, but I'm not sure if it could be improved.
scripts = { "script1": { "run": self.script1, "function": self.run_script1}, "script2": { "run": self.script2, "function": self.run_script2}, } for script in scripts: if scripts[script]["run"]: try: scripts[script]["function"]() except Exception as e: self.send_error_msg(f"{script} caused an exception: \"{e}\", continuing with next script.")