runtime
216 / 500
question 216 Modules & Packages · medium

Why does the nightly report run twice?

This file is the nightly module. The scheduler imports it and calls run_report("orders.csv") at 02:00, and the log shows the report twice, both saying 0 delivered orders, 0.00 total. A test that imports the module from another folder crashes with FileNotFoundError. Fix both problems; running the file by hand should still print the report once. (The scheduler's job is just import nightly, then nightly.run_report("orders.csv").)

Functionrun_report(path): prints "<n> delivered orders, <total, 2 decimals> total" and returns n
Fileorders.csv with columns order_id,status,total; statuses are lower case
Run as a scriptprints the report for orders.csv once
Importedprints nothing and reads no file
Examples
callrun_report('orders.csv')returns2
Expected output1 line
  1. 12 delivered orders, 84.07 total

Loading your progress…

Why does the nightly report run twice? — Python practice · Runtime