I'd like to bind
C-x C-e to
python-shell-send-region when I am in python major-mode.
In my config file, I have an add-hook for python mode, but I'd like this keybinding override to be removed/restored when I exit python major-mode.
The use-case for this is that I want to be able to switch my *scratch* buffer between modes and for things to continue making sense.
Is there an idiomatic way to achieve this?