获取 文件中的相关脚本内容 之间的内容。 参数: file_path: 要检查的文件路径 start_tag: 开始标签 end_tag: 结束标签 返回: 如果找到,返回开始标签和结束标签之间的内容;否则返回 None。
(file_path, start_tag, end_tag)
| 1 | def get_file_description(file_path, start_tag, end_tag): |
| 2 | """ |
| 3 | 获取 文件中的相关脚本内容 之间的内容。 |
| 4 | |
| 5 | 参数: |
| 6 | file_path: 要检查的文件路径 |
| 7 | start_tag: 开始标签 |
| 8 | end_tag: 结束标签 |
| 9 | |
| 10 | 返回: |
| 11 | 如果找到,返回开始标签和结束标签之间的内容;否则返回 None。 |
| 12 | """ |
| 13 | try: |
| 14 | with open(file_path, 'r', encoding='utf-8') as f: |
| 15 | content = f.read() |
| 16 | start_index = content.find(start_tag) |
| 17 | end_index = content.find(end_tag, start_index) |
| 18 | if start_index == -1 or end_index == -1: |
| 19 | return "1" |
| 20 | content_between_tags = content[start_index + len(start_tag):end_index].strip() |
| 21 | return content_between_tags |
| 22 | except FileNotFoundError: |
| 23 | print(f"文件未找到: {file_path}") |
| 24 | return "1" |
| 25 | except Exception as e: |
| 26 | print(f"发生错误: {e}") |
| 27 | return "1" |
no outgoing calls
no test coverage detected