import re test = 'argsLwk' def replaceHump(match): print(match) if match: line_fore, line_back = match.groups() print(line_back) print(line_fore) if len(line_back) == 1: line_back = line_back.lower() print(line_back) print(88888) print('_'.join([line_fore, line_back])) return '_'.join([line_fore, line_back]) # 调用 replace_hump 函数 将驼峰转为下划线命名 def hump2Line(strtf): ret = re.sub(r'([a-z])([A-Z]+)', replaceHump, strtf) print(ret) print(ret==re.sub(r"\d+", "_1", ret)) return re.sub(r"\d+", "_1", ret) # print(ret) a = hump2Line(test) print(a) # # <_sre.SRE_Match object; span=(3, 5), match='sL'> # L # s # l # 88888 # s_l # args_lwk # True # args_lwk
命名转换问题代码参考
猜你喜欢
转载自blog.csdn.net/xiao_xia_ming/article/details/82630346
今日推荐
周排行