0001import re
0002
0003_mixed_re = re.compile(r'([a-z])([A-Z]+)')
0004
0005def mixed_to_underscore(name):
0006    return _mixed_re.sub(
0007        lambda m: m.group(1)+'_'+m.group(2), name).lower()