mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect-gui.git
synced 2025-06-24 13:14:11 +08:00
9 lines
296 B
Python
9 lines
296 B
Python
|
import re
|
||
|
|
||
|
|
||
|
def camel_to_snake(name):
|
||
|
# 匹配大写字母并在前面添加下划线,然后将结果转换为小写
|
||
|
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
|
||
|
# 处理驼峰形式中的连续大写字母
|
||
|
s2 = re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1)
|
||
|
return s2.lower()
|