Feb-20-2019, 10:12 PM
You're defining functions that are local to the __init__ method, so they won't be accessible to the class as a whole. That can be fixed, but I'm not sure it should be. Dynamically generating code is pretty sketchy, and you should be very suspicious whenever you see the words "exec" or "eval" in source.
For starters, how are you planning on calling these dynamic functions?
What if one of the functions is "printText"? Would all the others stop working, because they're trying to use a version of printText which no longer exists?
I think it'd make more sense for you to load them as a dict, then have a single method that looks them up. So instead of
For starters, how are you planning on calling these dynamic functions?
What if one of the functions is "printText"? Would all the others stop working, because they're trying to use a version of printText which no longer exists?
I think it'd make more sense for you to load them as a dict, then have a single method that looks them up. So instead of
ML390.formFeed()
, you'd do ML390.dispatch("formFeed")
. Then that function would look something like: def dispatch(self, key): if key in self.data: return self.printText(self.data[key]) raise Exception(f"Invalid key: {key}")