""" 通用处理工具,字符串切分 """ from pathlib import Path def divide_string(s, num_parts): """ 切割字符串为指定均分的部分 :param s: 待切割的字符串 :param num_parts: 切割份数 :return: 切分结果 """ n = len(s) part_size = n // num_parts sizes = [part_size + 1 if i < n % num_parts else part_size for i in range(num_parts)] parts = [] start = 0 for size in sizes: parts.append(s[start:start + size]) start += size return parts def find_relative_directories(root_dir, target_dir): """ 查找指定目录下的目标目录相对路径 :param root_dir: 根目录 :param target_dir: 目标目录 :return: 根目录到目标目录的相对路径 """ root_path = Path(root_dir) yolox_paths = [] # 递归查找指定目录 for path in root_path.rglob(target_dir): if path.is_dir(): # 计算相对路径 relative_path = path.relative_to(root_path) yolox_paths.append(relative_path) return yolox_paths