base_utils.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2022/11/24 16:57
  3. # @Author : XuJiakai
  4. # @File : base_utils
  5. # @Software: PyCharm
  6. import json
  7. import jsonpath
  8. def to_list(string: str):
  9. string = string.strip()
  10. return [i.strip() for i in string.split("\n") if i.strip() != '']
  11. pass
  12. def parse_env_and_name(val, env):
  13. if '.' in val:
  14. tmp = val.split('.')
  15. env = tmp[0]
  16. val = tmp[1]
  17. return env, val
  18. def map_2_json_str(m: map):
  19. return json.dumps(m, indent=4, ensure_ascii=False, sort_keys=True)
  20. pass
  21. def json_path(data: map, key):
  22. if data is None:
  23. return None
  24. tmp_v = jsonpath.jsonpath(data, key)
  25. if tmp_v:
  26. return tmp_v[0]
  27. else:
  28. return None
  29. pass
  30. def tuple_max(*tu: tuple):
  31. result = None
  32. for i in tu:
  33. if result is None:
  34. result = i
  35. pass
  36. else:
  37. if i is tuple:
  38. if i[0] is not None and i[0] >= result[0]:
  39. result = i
  40. pass
  41. else:
  42. if i is not None and i >= result:
  43. result = i
  44. pass
  45. pass
  46. pass
  47. return result
  48. if __name__ == '__main__':
  49. print(tuple_max('4', None))
  50. pass