I have an app that creates Python code and runs it. During this process there are two method assignments that I’d like to clear as they create an error in the second run:
push = Writer.Push
...
def appPush(self):
push(self)
dumpRow(self)
...
Writer.Push=appPush
It’s a legacy code I have to fix. If you run this more than once, Python announces that there’s a recursion.
I’ve been looking for a way to clear the environment but ‘os.system(‘CLS’)’ didn’t help. How can I clean those assignments?
Thanks.
Edit:
It IS legacy code. I’m not very familiar with it yet. My app creates Python code that contains general stuff (like the bit I’ve posted above) and a translation of the user’s workflow to Python. If the user creates a flow that ends up calling ‘appPush’, the application has to be restarted after 1 run.
I can add stuff after the above code. What I’m looking for is a way to clear the interpreter’s environment from those assignment. Is it possible?
OK, I see what your problem is.
This code:
Would cause infinite recursion if
pushwere ever changed toappPush. What you basically want there is a decorator, so if you could change that to:This would keep the implied semantics of doing another
dumpRowevery time you used that bit of code.I don’t think you can fix your error by only adding code after the broken bit. You can’t ‘clear the environment’ and get your original
Writer.Pushback.