从批量输出里分门别类
真机上 checker.py 每个文件打若干行:错误、警告 或 OK。要在脚本里汇总,先在这里练:
lines = ["a.toy: 错误 未定义「x」@2:1", "a.toy: 警告 未使用「y」@1:5", "b.toy: OK 符号表 n:num", "c.toy: 错误 重复声明「z」@3:5", "c.toy: 错误 类型不匹配「num」「str」@4:1"]
errs, warns, ok = 0, 0, []
for l in lines:
name, rest = l.split(": ", 1)
if rest.startswith("错误"):
errs += 1
elif rest.startswith("警告"):
warns += 1
else:
ok.append(name)
print(str(errs) + "/" + str(warns) + "/" + ",".join(ok))
全部评论