def translate_non_alphanumerics(to_translate, translate_to='_'):
    not_letters_or_digits = '!"#%\'()*+,-./:;<=>?@[\\]^_`{|}~'
if isinstance(to_translate, str):
    translate_table = dict((ord(char), str(translate_to)) for char in
        not_letters_or_digits)
else:
    assert isinstance(to_translate, str)
translate_table = string.maketrans(not_letters_or_digits, translate_to *
    len(not_letters_or_digits))
return to_translate.translate(translate_table)
Как заставить str.translate работать со строками Unicode?