From d88afa7a586f4314b55ccd85182e6b234deacf7a Mon Sep 17 00:00:00 2001 From: Midgard Date: Sun, 6 Dec 2020 02:29:45 +0100 Subject: [PATCH] Move out of try block, fix typo, add line number --- table.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/table.py b/table.py index bc490b0..9128de8 100755 --- a/table.py +++ b/table.py @@ -37,17 +37,18 @@ for line_nr, line in enumerate(sys.stdin, start=1): try: del users[awardee][post_id][verifier] - # If no more verifiers left, the dict, this makes it easier to count - if not users[awardee][post_id]: - del users[awardee][post_id] - if not users[awardee]: - del users[awardee] except KeyError: - print(f"Trying to remove non-existing verification by {verifier}, looks like the file is corrupt!", file=sys.stderr) + print(f"Line {line_nr}: trying to remove non-existing verification by {verifier}, looks like the file is corrupt!", file=sys.stderr) + + # If no more verifiers left, clean up the dicts, this makes it easier to count + if not users[awardee][post_id]: + del users[awardee][post_id] + if not users[awardee]: + del users[awardee] continue - print(f"Couldn't parse line, looks like the file is corrupt: {line}", file=sys.stderr) + print(f"Couldn't parse line {line_nr}, looks like the file is corrupt: {line}", file=sys.stderr) for username, user_posts in users.items(): print(f"{username}: {len(user_posts)}")