I want to send instructions to a method as a pickleable object, then have that make changes. (Think track changes).
Current method:
I define a set of instructions:
instructions = { 0: { 'function': 'do_something_func', 'kwargs': { 'a':22, 'b':'hello, } } }
Inside my class I run the following:
for step, transformation in self.instructions.items(): eval('self.' + transformation['function'])(**transformation['kwargs'])
Generally, whenever eval
is used, it's unsafe and wrong. This also feels like a problem people would have solved.
So, what is the "right" way to do this? Rough criteria:
- Allow me to track and store a set of instructions (so I can reverse if required)
- Doesn't expose vulnerabilities.
- Scalable to ~100 transformations max.
- Human readable instructions if possible / easy to develop.
- I'm quite flexible on how these instructions are stored, I have initialy thought of using a yaml file, but gets more tricky whne using python specific arguments - e.g.
numpy.nan