class MoveFileCommand(object):

    def __init__(self, src, dest):
        self.src = src
self.dest = dest
os.rename(self.src, self.dest)

def undo(self):
    os.rename(self.dest, self.src)
undo_stack = []
undo_stack.append(MoveFileCommand('foo.txt', 'bar.txt'))
undo_stack.append(MoveFileCommand('bar.txt', 'baz.txt'))
undo_stack.pop().undo()
undo_stack.pop().undo()
General Command pattern and Command Dispatch pattern in Python