当前位置:   article > 正文

测试工程师与AI chatGPT,编写python读取xmind测试用例chatgtp+python+xmind

python读取xmind

背景

有用xmind写测试用例的吧,统计一个xmind的条,需要花大量的时间,还有要统计有多少条冒烟的,多少条不通过的,还有通过的条数。

需求

快速使用python,写一个简单的脚本,统计所有xmind节点,分别统计出,冒烟,通过,不通过的条数

方案

使用chatGPT编写python脚本,通过脚本读取xmind文件,统计特定标签数,特定的标签相当于表示冒烟用例,通过用例,不通过用例,解决人工统计的困难,通过程序统计一个比较准确的数值,允许有一定的偏差,偏差来自于xmind的版本,格式,编写规范等

过程

为chatGTP建立角色

先给chatGTP建立一个角色:测试开发、python开发

给chatGTP提出简单的需求

我:用python,分别读取xmind文件,每个一个画布
AI:要读取xmind文件,需要使用外部库xmind。首先,你需要使用pip在Python环境中安装xmind库。打开终端或命令行,输入以下命令进行安装:

pip install xmind

解析xmind文件

AI:安装完成后,就可以使用xmind库来读取并操作xmind文件了。

以下是一个读取xmind文件,并将每个画布输出为图片的代码示例:

  1. import xmind
  2. import os
  3. # 读取xmind文件
  4. workbook = xmind.load('/path/to/your/xmind/file.xmind')
  5. # 获取每个画布并输出为图片
  6. for sheet in workbook.getSheets():
  7. # 获取画布名称
  8. sheet_name = sheet.getTitle()
  9. # 创建输出目录
  10. output_dir = f'{os.getcwd()}/{sheet_name}'
  11. os.makedirs(output_dir, exist_ok=True)
  12. # 输出画布中的每个主题为图片
  13. for topic in sheet.getRootTopic().getSubTopics():
  14. # 获取主题文本
  15. topic_title = topic.getTitle()
  16. # 创建输出文件路径
  17. output_file = f'{output_dir}/{topic_title}.png'
  18. # 输出主题为图片
  19. topic.getImage(output_file)

AI对代码的解析

AI:代码中,xmind.load()方法读取指定路径的xmind文件,并返回一个workbook对象。getSheets()方法获取xmind文件中的所有画布。遍历每个画布,获取画布名称并创建输出目录。

然后,遍历每个画布中的主题,获取主题文字并创建输出文件的路径。getImage()方法将主题输出为png格式的图片。

这个示例代码可以帮助你开始读取和处理xmind文件。你可以根据自己的需求,进一步扩展和优化代码。


AI明细是要输出图片,这也明细不是我的本意,我意思是输出每个sheet的名字

矫正AI的理解重写需求

我:只需要在python里面print一下所有的画布名称

AI:

  1. import xmind
  2. # 读取xmind文件
  3. workbook = xmind.load('/path/to/your/xmind/file.xmind')
  4. # 遍历每个画布并打印画布名称
  5. for sheet in workbook.getSheets():
  6. print(sheet.getTitle())
  7. 代码中,workbook.getSheets()方法获取xmind文件中的所有画布,
  8. 然后使用for循环遍历每个画布,打印出画布的名称。
  9. 运行代码,即可在控制台上看到所有画布的名称。

我:xmind这个库无法打开最新的xmind

AI:如果xmind库无法打开最新格式的xmind文件,可能需要使用最新的xmind库或者其他支持最新xmind格式的库。

可以尝试使用xmind-sdk-python库来打开最新版本的xmind文件,它是Xmind的官方开发工具,支持最新版本的xmind文件。

以下是一个使用xmind-sdk-python库打开xmind文件,并打印所有画布名称的示例代码:

  1. from xmind import xmind_to_dict
  2. # 读取xmind文件
  3. xmind_file = '/path/to/your/xmind/file.xmind'
  4. # 将xmind文件转换成字典
  5. xmind_dict = xmind_to_dict(xmind_file)
  6. # 获取画布列表
  7. sheets = xmind_dict.get('sheets')
  8. # 打印所有画布名称
  9. if sheets:
  10. for sheet in sheets:
  11. print(sheet.get('title'))
  12. 代码中,xmind_to_dict()方法将xmind文件读入,并将其转换成一个包含所有信息的字典。
  13. 然后通过获取字典中的'sheets'键,获取所有画布的信息。
  14. 对于每个画布,使用get()方法获取名称信息并打印。
  15. 这个示例代码可以帮助你使用xmind-sdk-python库,打开最新版本的xmind文件并打印出画布名称。
  16. 你可以根据自己的需求,进一步扩展和优化代码。

指定AI使用指定类库

我:用这个库:xmindparser

AI:xmindparser是第三方库,可以解析最新版本Xmind文件,进行导入和导出,同时提供方便的API,方便对Xmind文件进行修改和处理。以下是一个使用xmindparser库读取xmind文件,并打印所有画布名称的代码示例:

  1. from xmindparser import xmind_to_dict
  2. # 读取xmind文件
  3. xmind_file = '/path/to/your/xmind/file.xmind'
  4. # 将xmind文件转换成字典
  5. xmind_dict = xmind_to_dict(xmind_file)
  6. # 获取画布列表
  7. sheets = xmind_dict.get('topic-refs')
  8. # 打印所有画布名称
  9. if sheets:
  10. for sheet in sheets:
  11. sheet_id = sheet.get('id')
  12. sheet_title = xmind_dict.get(sheet_id, {}).get('title')
  13. print(sheet_title)
  14. 代码中,xmind_to_dict()方法读取xmind文件,并将其转换成一个字典。
  15. 使用xmind_dict.get()方法,获取字典中的'topic-refs'键,它包含了所有画布的引用。
  16. 对于每个画布引用,获取它的id并使用xmind_dict.get()方法获取对应的画布信息,
  17. 包括标题信息,并打印出标题信息。
  18. 这个示例代码可以帮助你使用xmindparser库,打开最新版本的xmind文件并打印出画布名称。
  19. 你可以根据自己的需求,进一步扩展和优化代码。

到这里把代码贴上去,还是有报错的,再一次调教一下AI,再完善一下需求的方向

我:用python的xmindparser库,分别读取xmind文件中每个画布的名称

AI:使用xmindparser库,可以通过以下代码读取xmind文件中每个画布的所有主题及其名称信息:

  1. from xmindparser import xmind_to_dict
  2. # 读取xmind文件
  3. xmind_file = '/path/to/your/xmind/file.xmind'
  4. # 将xmind文件转换成字典
  5. xmind_dict = xmind_to_dict(xmind_file)
  6. # 获取画布列表
  7. sheets = xmind_dict.get('topic-refs')
  8. # 遍历所有画布的主题并打印主题名称
  9. if sheets:
  10. for sheet in sheets:
  11. sheet_id = sheet.get('id')
  12. sheet_title = xmind_dict.get(sheet_id, {}).get('title')
  13. sheet_topics = xmind_dict.get(sheet_id, {}).get('topics')
  14. if sheet_topics:
  15. for topic in sheet_topics:
  16. topic_title = topic.get('title')
  17. print(f'画布: {sheet_title}, 主题: {topic_title}')
  18. 代码中,xmind_to_dict()方法读取xmind文件,并将其转换成一个字典。
  19. 使用xmind_dict.get()方法,获取字典中的'topic-refs'键,它包含了所有画布的引用。
  20. 对于每个画布引用,获取它的id,并使用xmind_dict.get()方法获取对应的画布信息,包括标题信息和主题信息。
  21. 对于每个画布,遍历主题信息,获取主题标题信息并打印。
  22. 这个示例代码可以帮助你使用xmindparser库读取xmind文件中所有画布的主题及其名称信息。
  23. 你可以根据自己的需求,进一步扩展和优化代码。

'list' object has no attribute 'get'

运行之后,发送报错了,把错误在抛给gtp,sheets = xmind_dict.get('topic-refs')
AttributeError: 'list' object has no attribute 'get'

AI:如果你遇到'list' object has no attribute 'get'错误,可能是由于读取xmind文件后返回了列表而非字典对象。

这种情况下,你可以尝试使用以下代码,从列表中获取字典对象:

  1. from xmindparser import xmind_to_dict
  2. # 读取xmind文件
  3. xmind_file = '/path/to/your/xmind/file.xmind'
  4. # 将xmind文件转换成字典或列表
  5. xmind_data = xmind_to_dict(xmind_file)
  6. # 如果返回的是列表,则获取第一个元素
  7. if isinstance(xmind_data, list):
  8. xmind_data = xmind_data[0]
  9. # 获取画布列表
  10. sheets = xmind_data.get('topic-refs')
  11. # 遍历所有画布的主题并打印主题名称
  12. if sheets:
  13. for sheet in sheets:
  14. sheet_id = sheet.get('id')
  15. sheet_title = xmind_data.get(sheet_id, {}).get('title')
  16. sheet_topics = xmind_data.get(sheet_id, {}).get('topics')
  17. if sheet_topics:
  18. for topic in sheet_topics:
  19. topic_title = topic.get('title')
  20. print(f'画布: {sheet_title}, 主题: {topic_title}')
  21. 代码中,使用isinstance()方法判断返回值的类型,如果是列表类型,则获取第一个元素。
  22. 获取画布列表后,遍历所有画布的主题并打印主题名称。
  23. 使用这个代码可以解决'list' object has no attribute 'get'错误,帮助你使用xmindparser库读取xmind文件中所有画布的主题及其名称信息。

 运行了一下代码,结果打印为空

继续给AI抛出错误:打印的结果为什么会为空?

下面是AI给出的意见,大概是个说,xmind的文件没有对应字段

可以先通过xmind的类库打开文件,读取并打印信息,看看文件的字段名叫什么

from xmind import xmind_to_dict

# 读取xmind文件
xmind_file = '/path/to/your/xmind/file.xmind'

# 将xmind文件转换成字典
xmind_dict = xmind_to_dict(xmind_file)

 我:我的内容不包含topic-refs,替换成‘title’,而且个列表

AI:如果你的xmind文件中没有topic-refs键,但是有title键,可以按照以下代码读取画布名称和主题名称。

  1. from xmindparser import xmind_to_dict
  2. # 读取xmind文件
  3. xmind_file = '/path/to/your/xmind/file.xmind'
  4. # 将xmind文件转换成字典或列表
  5. xmind_data = xmind_to_dict(xmind_file)
  6. # 如果返回的是列表,则获取第一个元素
  7. if isinstance(xmind_data, list):
  8. xmind_data = xmind_data[0]
  9. # 获取画布列表
  10. sheets = xmind_data.get('title')
  11. # 处理每个画布
  12. for sheet in sheets:
  13. sheet_title = sheet['title']
  14. # 处理画布中的主题
  15. root_topic = sheet.get('topics', {})
  16. topics = root_topic.get('children', [])
  17. # 处理每个主题
  18. for topic in topics:
  19. topic_title = topic.get('title', '')
  20. print(f'画布: {sheet_title}, 主题: {topic_title}')
  21. 代码中,我们先使用xmindparser库将xmind文件转换成字典或列表格式。
  22. 如果返回的是一个列表,则需要获取列表中的第一个元素。
  23. 然后,获取画布列表。在这种情况下,'title'键返回的值是一个列表,我们需要处理每个画布。
  24. 对于每个画布,获取其标题,并处理其中的主题。在这个例子中,我们使用根主题作为画布的主题,
  25. 然后获取主题下的所有子主题。对于每个主题,获取其标题,打印输出画布名称和主题名称。
  26. 这个代码可以帮助你使用xmindparser库读取xmind文件中所有画布和主题名称信息,
  27. 并对其进行处理和扩展。

string indices must be integers

我:sheet_title = sheet['title']
TypeError: string indices must be integers

AI:如果你遇到TypeError: string indices must be integers错误,可能是由于代码中对字符串类型的变量进行了索引,而字符串类型是不支持索引操作的。

针对这种情况,你可以使用以下代码:

  1. from xmindparser import xmind_to_dict
  2. # 读取xmind文件
  3. xmind_file = '/path/to/your/xmind/file.xmind'
  4. # 将xmind文件转换成字典或列表
  5. xmind_data = xmind_to_dict(xmind_file)
  6. # 如果返回的是列表,则获取第一个元素
  7. if isinstance(xmind_data, list):
  8. xmind_data = xmind_data[0]
  9. # 获取画布列表
  10. sheets = xmind_data.get('title')
  11. # 处理每个画布
  12. for sheet in sheets:
  13. if isinstance(sheet, str):
  14. sheet_title = sheet
  15. else:
  16. sheet_title = sheet.get('title', '')
  17. # 处理画布中的主题
  18. root_topic = sheet.get('topics', {})
  19. topics = root_topic.get('children', [])
  20. # 处理每个主题
  21. for topic in topics:
  22. topic_title = topic.get('title', '')
  23. print(f'画布: {sheet_title}, 主题: {topic_title}')
  24. 在这个代码中,我们增加了一个判断:如果当前画布的类型是字符串,
  25. 直接将其作为画布标题;否则,使用get()方法获取其标题,如果无法获取,则将其设为空字符串。
  26. 这个代码可以解决TypeError: string indices must be integers错误,
  27. 帮助你使用xmindparser库读取xmind文件中所有画布和主题名称信息,并对其进行处理和扩展。

AttributeError: 'str' object has no attribute

我:root_topic = sheet.get('topics', {}) AttributeError: 'str' object has no attribute 'get'

AI:

如果你遇到了AttributeError: 'str' object has no attribute 'get'错误,在这种情况下是因为原先的代码设定先判断json中的'title'键是否存在,若存在后继续操作,但'title'返回的是字符串,字符串类型是不支持使用get方法的。

因此,需要先判断获取到的变量是否为字典类型,如果是则使用get()方法获取'topics'键对应的值,否则设置root_topic为一个空字典。

修改后的代码如下:

  1. from xmindparser import xmind_to_dict
  2. # 读取xmind文件
  3. xmind_file = '/path/to/your/xmind/file.xmind'
  4. # 将xmind文件转换成字典或列表
  5. xmind_data = xmind_to_dict(xmind_file)
  6. # 如果返回的是列表,则获取第一个元素
  7. if isinstance(xmind_data, list):
  8. xmind_data = xmind_data[0]
  9. # 获取画布列表
  10. sheets = xmind_data.get('title')
  11. # 处理每个画布
  12. for sheet in sheets:
  13. if isinstance(sheet, str):
  14. sheet_title = sheet
  15. else:
  16. sheet_title = sheet.get('title', '')
  17. # 处理画布中的主题
  18. if isinstance(sheet, dict):
  19. root_topic = sheet.get('topics', {})
  20. topics = root_topic.get('children', [])
  21. else:
  22. topics = []
  23. # 处理每个主题
  24. for topic in topics:
  25. topic_title = topic.get('title', '')
  26. print(f'画布: {sheet_title}, 主题: {topic_title}')
  27. 在这个代码中,我们增加了一个判断:如果当前画布的类型是字典,
  28. 使用get()方法获取'topics'键对应的值,否则将topics设置为空列表。
  29. 这个代码可以解决AttributeError: 'str' object has no attribute 'get'错误,
  30. 帮助你使用xmindparser库读取xmind文件中所有画布和主题名称信息,并对其进行处理和扩展。

来到这里,代码没有报错,运行也没有打印结果,由于上面我们看过数据格式,在一次告诉AI我们的结果格式

向AI提出我需要的结果

我:我告诉你一下,这是xmind_data结果:[{'title': '画布 1', 'topic': {'title': '中心主题', 'topics': [{'title': '分支主题 1', 'makers': ['tag-red']}, {'title': '分支主题 2', 'makers': ['tag-orange']}, {'title': '分支主题 3', 'makers': ['tag-green'], 'topics': [{'title': '子主题 1', 'makers': ['priority-1']}, {'title': '子主题 2', 'makers': ['flag-red']}]}, {'title': '分支主题 4'}]}, 'structure': 'org.xmind.ui.map.unbalanced'}, {'title': '画布 2', 'topic': {'title': '中心主题', 'topics': [{'title': '分支主题 1'}, {'title': '分支主题 2'}]}, 'structure': 'org.xmind.ui.map.unbalanced'}]

AI:好的,根据你提供的内容,可以按照以下代码处理xmind_data:

  1. from xmindparser import xmind_to_dict
  2. # 读取xmind文件
  3. xmind_file = '/path/to/your/xmind/file.xmind'
  4. # 将xmind文件转换成字典或列表
  5. xmind_data = xmind_to_dict(xmind_file)
  6. # 处理每个画布
  7. for sheet in xmind_data:
  8. sheet_title = sheet.get('title', '')
  9. # 处理画布中的主题
  10. root_topic = sheet.get('topic', {})
  11. topics = root_topic.get('topics', [])
  12. # 处理每个主题
  13. for topic in topics:
  14. topic_title = topic.get('title', '')
  15. print(f'画布: {sheet_title}, 主题: {topic_title}')

来到这里由于有运行结果,当然结果还是需要进一步优化的,需要优化画布的名称重复输出

我:只需要打印,画布名称就可以了

AI: 如果你只需要打印画布名称,可以按照以下代码处理xmind_data:

  1. from xmindparser import xmind_to_dict
  2. # 读取xmind文件
  3. xmind_file = '/path/to/your/xmind/file.xmind'
  4. # 将xmind文件转换成字典或列表
  5. xmind_data = xmind_to_dict(xmind_file)
  6. # 打印每个画布的名称
  7. for sheet in xmind_data:
  8. sheet_title = sheet.get('title', '')
  9. print(f'画布: {sheet_title}')
  10. 这个代码会遍历xmind_data中所有的画布,获取画布的名称并打印出来。
  11. 如果你需要获取更多的信息,比如主题的数量或者关系,可以对代码进行相应的修改,
  12. 比如添加一个计数器获取主题数量等。

这里只统计了一个结果,需要遍历所有结果出来

我:继续完善这个代码,for循环遍历xmind_data,得到每个一个画布,循环遍历找到每个画布里面的makers键的值,且统计值的个数

AI:继续完善这个代码,for循环遍历xmind_data,得到每个一个画布,循环遍历找到每个画布里面的makers键的值,且统计值的个数

  1. from collections import Counter
  2. from xmindparser import xmind_to_dict
  3. # 读取xmind文件
  4. xmind_file = '/path/to/your/xmind/file.xmind'
  5. # 将xmind文件转换成字典或列表
  6. xmind_data = xmind_to_dict(xmind_file)
  7. # 遍历每个画布
  8. for sheet in xmind_data:
  9. sheet_title = sheet.get('title')
  10. markers = []
  11. # 遍历每个主题,获取标签列表
  12. for topic in sheet.get('topic', {}).get('topics', []):
  13. markers += topic.get('markers', [])
  14. # 统计每个标签出现的次数
  15. marker_count = Counter(markers)
  16. # 输出结果
  17. print(f'画布: {sheet_title}')
  18. for marker, count in marker_count.items():
  19. print(f'标签:{marker},出现次数:{count}')
  20. print('\n')

我:完善代码makers的值分别为:tag-green,tag-red,tag-yellow

AI:好的,如果你需要在上面的代码基础上进一步筛选标签,使其仅包含值为’tag-green’、'tag-red’和’tag-yellow’的标签,并统计其出现次数,可以按照以下代码进行修改:

  1. from collections import Counter
  2. from xmindparser import xmind_to_dict
  3. # 读取xmind文件
  4. xmind_file = '/path/to/your/xmind/file.xmind'
  5. # 将xmind文件转换成字典或列表
  6. xmind_data = xmind_to_dict(xmind_file)
  7. # 遍历每个画布
  8. for sheet in xmind_data:
  9. sheet_title = sheet.get('title')
  10. markers = []
  11. # 遍历每个主题,获取标签列表
  12. for topic in sheet.get('topic', {}).get('topics', []):
  13. for marker in topic.get('markers', []):
  14. if marker in ['tag-green', 'tag-red', 'tag-yellow']:
  15. markers.append(marker)
  16. # 统计每个标签出现的次数
  17. marker_count = Counter(markers)
  18. # 输出结果
  19. print(f'画布: {sheet_title}')
  20. for marker, count in marker_count.items():
  21. print(f'标签:{marker},出现次数:{count}')
  22. print('\n')

我:我告诉你一下,这是xmind_data结果,有‘画布1’和‘画布2’,分别统计出'tag-green', 'tag-red', 'tag-yellow'的标签数量:[{'title': '画布 1', 'topic': {'title': '中心主题', 'topics': [{'title': '分支主题 1', 'makers': ['tag-red']}, {'title': '分支主题 2', 'makers': ['tag-orange']}, {'title': '分支主题 3', 'makers': ['tag-green'], 'topics': [{'title': '子主题 1', 'makers': ['priority-1']}, {'title': '子主题 2', 'makers': ['flag-red']}]}, {'title': '分支主题 4'}]}, 'structure': 'org.xmind.ui.map.unbalanced'}, {'title': '画布 2', 'topic': {'title': '中心主题', 'topics': [{'title': '分支主题 1'}, {'title': '分支主题 2'}]}, 'structure': 'org.xmind.ui.map.unbalanced'}] 

AI:好的,那么可以按照如下代码对xmind_data进行进一步筛选和统计:

  1. from collections import Counter
  2. from xmindparser import xmind_to_dict
  3. # 读取xmind文件
  4. xmind_file = '/path/to/your/xmind/file.xmind'
  5. # 将xmind文件转换成字典或列表
  6. xmind_data = xmind_to_dict(xmind_file)
  7. # 定义要统计的标签
  8. target_tags = ['tag-green', 'tag-red', 'tag-yellow']
  9. # 遍历每个画布
  10. for sheet in xmind_data:
  11. sheet_title = sheet.get('title')
  12. markers = []
  13. # 遍历每个主题,获取标签列表
  14. for topic in sheet.get('topic', {}).get('topics', []):
  15. makers = topic.get('makers', [])
  16. # 筛选出目标标签
  17. target_makers = [maker for maker in makers if maker in target_tags]
  18. markers.extend(target_makers)
  19. # 统计每个标签出现的次数
  20. marker_count = Counter(markers)
  21. # 输出结果
  22. print(f'画布: {sheet_title}')
  23. for target_tag in target_tags:
  24. count = marker_count[target_tag]
  25. print(f'标签:{target_tag},出现次数:{count}')
  26. print('\n')

我:然后将这几个标签的数相加'tag-green', 'tag-red', 'tag-yellow'

AI:

  1. from collections import Counter
  2. from xmindparser import xmind_to_dict
  3. # 读取xmind文件
  4. xmind_file = '/path/to/your/xmind/file.xmind'
  5. # 将xmind文件转换成字典或列表
  6. xmind_data = xmind_to_dict(xmind_file)
  7. # 定义要统计的标签
  8. target_tags = ['tag-green', 'tag-red', 'tag-yellow']
  9. # 初始化标签数量
  10. total_count = 0
  11. # 遍历每个画布
  12. for sheet in xmind_data:
  13. markers = []
  14. # 遍历每个主题,获取标签列表
  15. for topic in sheet.get('topic', {}).get('topics', []):
  16. makers = topic.get('makers', [])
  17. # 筛选出目标标签
  18. target_makers = [maker for maker in makers if maker in target_tags]
  19. markers.extend(target_makers)
  20. # 统计每个标签出现的次数
  21. marker_count = Counter(markers)
  22. # 累加每个目标标签的出现次数
  23. for target_tag in target_tags:
  24. count = marker_count[target_tag]
  25. total_count += count
  26. print(f'标签:{target_tag},出现次数:{count}')
  27. print(f"目标标签共出现了{total_count}次\n")

 最后面,就不断和AI沟通,完善代码

  1. from xmindparser import xmind_to_dict
  2. xmind_file = 'test.xmind'
  3. xmind_dict = xmind_to_dict(xmind_file)
  4. def count_titles_and_tags(topics):
  5. """
  6. 递归地统计所有的title和tag数量
  7. """
  8. title_count = len(topics) # 统计当前主题块的数量
  9. tag_red_count = 0
  10. tag_orange_count = 0
  11. tag_green_count = 0
  12. for topic in topics:
  13. if 'makers' in topic and 'tag-red' in topic['makers']:
  14. tag_red_count += 1
  15. if 'makers' in topic and 'tag-yellow' in topic['makers']:
  16. tag_orange_count += 1
  17. if 'makers' in topic and 'tag-green' in topic['makers']:
  18. tag_green_count += 1
  19. if 'topics' in topic:
  20. sub_topics = topic['topics']
  21. sub_counts = count_titles_and_tags(sub_topics)
  22. title_count += sub_counts[0]
  23. tag_red_count += sub_counts[1]
  24. tag_orange_count += sub_counts[2]
  25. tag_green_count += sub_counts[3]
  26. return title_count, tag_red_count, tag_orange_count, tag_green_count
  27. # 统计所有的title和tag数量
  28. # total_counts = count_titles_and_tags(xmind_dict[0]['topic']['topics'])
  29. # print("Total number of titles:", total_counts[0])
  30. # print("Total number of tag-red:", total_counts[1])
  31. # print("Total number of tag-orange:", total_counts[2])
  32. # print("Total number of tag-green:", total_counts[3])
  33. # for canvas in xmind_dict:
  34. # print("Canvas name:", canvas['title'])
  35. # topics = canvas['topic']['topics']
  36. # total_counts = count_titles_and_tags(topics)
  37. # print("Total number of titles in canvas:", total_counts[0])
  38. # print("Total number of tag-red in canvas:", total_counts[1])
  39. # print("Total number of tag-orange in canvas:", total_counts[2])
  40. # print("Total number of tag-green in canvas:", total_counts[3])
  41. # 初始化总计数器
  42. total_counts = [0, 0, 0, 0] # title计数器,tag-red计数器,tag-orange计数器,tag-green计数器
  43. for canvas in xmind_dict:
  44. print("Canvas name:", canvas['title'])
  45. topics = canvas['topic']['topics']
  46. canvas_counts = count_titles_and_tags(topics)
  47. print("Total number of titles in canvas:", canvas_counts[0])
  48. print("Total number of tag-red in canvas:", canvas_counts[1])
  49. print("Total number of tag-orange in canvas:", canvas_counts[2])
  50. print("Total number of tag-green in canvas:", canvas_counts[3])
  51. # 累加计数器
  52. total_counts[0] += canvas_counts[0] # title计数器累加
  53. total_counts[1] += canvas_counts[1] # tag-red计数器累加
  54. total_counts[2] += canvas_counts[2] # tag-orange计数器累加
  55. total_counts[3] += canvas_counts[3] # tag-green计数器累加
  56. # 输出总计数器结果
  57. print("Canvas name:总计数")
  58. print("Total number of titles:", total_counts[0])
  59. print("Total number of tag-red:", total_counts[1])
  60. print("Total number of tag-orange:", total_counts[2])
  61. print("Total number of tag-green:", total_counts[3])

运行结果

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/917228?site
推荐阅读
相关标签
  

闽ICP备14008679号