A side-effect of these changes is that \a no longer gets shown as '\a', but '\0x07'. Some characters, i.e. \n and \t, are still shown as '\n' and '\t' respectively, so this comes simply down to repr() behaviour. However, I do believe it's worth it to get rid of that ugly code duplication.