import redef camel_to_snake(camel_str):""" 将驼峰形式的字符串转换为下划线形式。参数:camel_str (str): 驼峰形式的字符串,例如 "userName"。返回:str: 转换后的下划线形式的字符串,例如 "user_name"。""" s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', camel_str)return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()import redef snake_to_camel(snake_str):""" 将下划线形式的字符串转换为驼峰形式。参数:snake_str (str): 下划线形式的字符串,例如 "user_name"。返回:str: 转换后的驼峰形式的字符串,例如 "userName"。""" components = snake_str.split('_')return components[0] + "".join(x.title() for x in components[1:])