123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- # -*- coding: utf-8 -*-
- # @Time : 2023/7/21 14:45
- # @Author : XuJiakai
- # @File : str_utils
- # @Software: PyCharm
- import json
- import re
- def json_str_2_list(json_str, key: str):
- if json_str is None:
- return []
- try:
- if type(json_str) == dict or type(json_str) == list:
- j = json_str
- else:
- j = json.loads(json_str)
- result = []
- for i in j:
- result.append(i[key])
- pass
- return result
- pass
- except Exception:
- return []
- pass
- pass
- def pascal_case_to_snake_case(camel_case: str):
- """
- 驼峰转下划线
- :param camel_case:
- :return:
- """
- snake_case = re.sub(r"(?P<key>[A-Z])", r"_\g<key>", camel_case)
- return snake_case.lower().strip('_')
- pass
- def snake_case_to_pascal_case(snake_case: str):
- """
- 下划线转驼峰
- :param snake_case:
- :return:
- """
- words = snake_case.split('_')
- return ''.join(word.title() for word in words)
- pass
- if __name__ == '__main__':
- res = pascal_case_to_snake_case("CompanyCourtOpenAnnouncement")
- print(pascal_case_to_snake_case("CompanyCourtOpenAnnouncement"))
- print(snake_case_to_pascal_case(res))
- pass
|