Source code for pyquickhelper.texthelper.code_helper

# -*- coding: utf-8 -*-
"""
Some functions about diacritics


:githublink:`%|py|6`
"""
import re
import keyword


[docs]def change_style(name): """ Switches from *AaBb* into *aa_bb*. :param name: name to convert :return: converted name Example: .. runpython:: :showcode: from pyquickhelper.texthelper import change_style print("changeStyle --> {0}".format(change_style('change_style'))) :githublink:`%|py|25` """ s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) s2 = re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() return s2 if not keyword.iskeyword(s2) else s2 + "_"