Skip to content

Fix ModuleNotFoundError in football_final.py and misnamed weather function - #811

Open
realpython-bot wants to merge 1 commit into
realpython:masterfrom
realpython-bot:csv-parsing-fix-broken-import
Open

Fix ModuleNotFoundError in football_final.py and misnamed weather function#811
realpython-bot wants to merge 1 commit into
realpython:masterfrom
realpython-bot:csv-parsing-fix-broken-import

Conversation

@realpython-bot

Copy link
Copy Markdown
Contributor

Found while reviewing a content update to Python Practice Problems: Parsing CSV Files.

The bug: full_code/football_final.py does not run

File "full_code/football_final.py", line 14, in <module>
    import csv_reader
ModuleNotFoundError: No module named 'csv_reader'

This folder only ever shipped csv_parser.py — there is no csv_reader.py in the tree, and there is none in the tutorial either. The article's own final listing imports csv_parser, so the module name here was simply wrong. Anyone downloading the materials and running the final football solution hits this immediately. Reproduced on current master before the fix.

Two call sites: the import at line 14 and the csv_reader.get_next_result(...) reference at line 25.

Also: get_name_and_avgget_day_and_avg in weather_final.py

That function returns day_number — never a name:

def get_day_and_avg(day_stats):
    day_number = int(day_stats["Day"])
    avg = (int(day_stats["MxT"]) + int(day_stats["MnT"])) / 2
    return day_number, avg

weather_v2.py, two steps earlier in the same narrative, already calls it get_day_and_avg; the final file silently renamed it. The matching fix is going into the article in the same pass, so the two stay in sync.

Its sibling get_name_and_diff in football_final.py is deliberately left alone — that one really does return a team name.

Verification

  • Reproduced the ModuleNotFoundError on unmodified master.
  • After the change, both football_final and weather_final import cleanly.
  • The folder's pytest suite passes 16/16 under Python 3.14 with pytest 9.1.1 and pandas 3.0.5.

Known, not fixed here

README.md still shows a console block claiming Python 3.7.1, pytest-6.2.1, py-1.10.0, pluggy-0.13.1. That's stale against the toolchain the article now documents, but refreshing it means regenerating the sample output, which is a bigger change than this fix — worth a follow-up.

Prepared during a written-content maintenance review (reviewer: Martin Breuss).

🤖 Generated with Claude Code

full_code/football_final.py did `import csv_reader`, but this folder only
ever shipped csv_parser.py. Anyone running the final football solution hit:

    File "full_code/football_final.py", line 14, in <module>
        import csv_reader
    ModuleNotFoundError: No module named 'csv_reader'

The tutorial's own final listing imports csv_parser, so the module name here
was simply wrong.

Also renames get_name_and_avg -> get_day_and_avg in weather_final.py. That
function returns `day_number`, never a name, and weather_v2.py two steps
earlier already calls it get_day_and_avg -- the final file silently renamed
it. Its sibling get_name_and_diff in football_final.py is left alone,
because that one does return a team name.

Verified: both modules import cleanly and the folder's pytest suite passes
16/16 under Python 3.14 with pytest 9.1.1 and pandas 3.0.5.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant