Answering my own question because I have found the answer here:
https://superuser.com/questions/212446/binding-backward-kill-word-to-ctrlw
Short answer is: in addition to adding
import readline
readline.parse_and_bind('"\\C-w": backward-kill-word')
to ~/.pythonrc.py
, execute this:
stty werase undef
sometime before running Python in the same terminal. This will get control over C-w
from the terminal.
Not deleting the question in case someone stumbles into the issue in Python interactive context.