从批量输出里抠出数字
真机上 parser.py 对每个文件打一行 prog3.toy: OK 4条语句 或 prog5.toy: 错误 期待「;」遇到「let」@2:1。要在脚本里汇总,先在这里练:
lines = ["prog1.toy: OK 3条语句", "prog2.toy: 错误 期待「;」遇到「let」@2:1", "prog3.toy: OK 4条语句"]
total = 0
bad = []
for l in lines:
name, rest = l.split(": ", 1)
if rest.startswith("OK "):
total += int(rest[3:].rstrip("条语句"))
else:
bad.append(name + "@" + rest.split("@")[1])
print(str(total) + "/" + ",".join(bad))
全部评论