文件示例
代码
def get_classes_id(self,classtxt_path):
re_dict = {}
with open(classtxt_path,mode='r',encoding='utf-8') as f:
line = f.readline()
while line:
c_class,id = line.split(',')
re_dict[c_class.strip()] = id.strip()
line = f.read()
return re_dict
结果
{'cat': '0', 'dog': '1'}
{'cat': '0', 'dog': '1'}