使用 re.sub 转换字符串大小写
import re
def pythonReSubDemo(inputStr):
"""
demo Pyton re.sub
"""
# inputStr = "recordInvalidDate"
def to_lower(matched):
s = matched.group(0).lower()
t = f'_{s}'
return t
replaced_str = re.sub(r"([A-Z])", to_lower, inputStr)
"""
# 转换成字典
s_input = inputStr.strip()
s_replaced = replaced_str.strip()
dic = {
s_input: s_replaced
}
print(dic)
"""
print('replaced_str', replaced_str) # record_invalid_date 大写字母转成下划线 + 小写字母
if name == "main":
s1 = """
'economicType',
'companyHouseType',
'propertyType',
'propertyOwner',
'propertyDate',
'grossArea',
'systemSupplier',
'parkLocationClass',
'workerNum',
'parkCharger',
'mobilePhone',
'telPhone',
"""
s2 = s1.split(',')
for i in s2:
pythonReSubDemo(i)
人生苦短,我用python