import os import re # 工具类 class AiUtils(object): @classmethod def findNumber(cls, str): # 使用正则表达式匹配数字 match = re.search(r'\d+', str) if match: return int(match.group()) # 将匹配到的数字转换为整数 return None # 如果没有找到数字,返回 None # 根据名称获取图片地址 @classmethod def pathWithName(cls, name): current_file_path = os.path.abspath(__file__) # 获取当前文件所在的目录(即script目录) current_dir = os.path.dirname(current_file_path) # 由于script目录位于项目根目录下一级,因此需要向上一级目录移动两次 project_root = os.path.abspath(os.path.join(current_dir, '..')) # 构建资源文件的完整路径,向上两级目录,然后进入 resources 目录 resource_path = os.path.abspath(os.path.join(project_root, 'resources', name + ".jpg")).replace('/', '\\') return resource_path