例如:>>> convert('CamelCase')'camel_case'
例子:
>>> convert('CamelCase') 'camel_case'
避免使用库和正则表达式:
def camel_to_snake(s): return ''.join(['_'+c.lower() if c.isupper() else c for c in s]).lstrip('_')
>>> camel_to_snake('ThisIsMyString') 'this_is_my_string'