Paul's Python CoursePPC

Project 6 of 20, for Neil

Log Analyser

Count the errors in the flight log every system on Neil's drone writes to, and survive the lines that make no sense.

About 60 minutes, in 14 steps.

Sign up free to open itLog in

Act 2 needs a free account, so your work is saved as you go. Act 1 is open to everyone.

The brief

  • NeilEverything on my drone writes to the one flight log, the GPS, the motors, the battery, the camera and the radio.
  • NeilI wrote the script that reads it back in my first year, and it stops at the first bad line.
  • NeilSunday's flight has got a lot of bad lines, and the drone ended up coming down in a hedge.
  • PaulHave a proper read of it before you change anything, because old code usually has its reasons.

Neil's script reads flight.log and counts the errors from each system on the drone. It stops dead at the first line it can't read.

Change it so it reads every line it can, skips the ones it can't, and says which it skipped and why. Blank lines aren't problems, and a level in lower case still counts.

What it prints
11 entries read
Errors by system:
  camera: 2
  gps: 2
  motors: 1
Skipped 3 lines:
  line 6: expected 4 parts, got 3
  line 9: unknown level WARNING
  line 12: expected 4 parts, got 1

What you learn

What's in it

  1. Stopping on purpose
  2. The wrong shape
  3. Read it before you touch it
  4. Catching it, and keeping the message
  5. Catching it
  6. Whatever happens
  7. Else, and finally
  8. Expect the odd line
  9. Tidied, then checked
  10. How Paul would do it
  11. Fix Caitlin's version
  12. Teach it some manners
  13. Ship it