I wrote this code for scourgify.py :-

import sys
import csv
import os

if len(sys.argv) < 3:
        sys.exit("Too few Command-line argument")
elif len(sys.argv) > 3 :
        sys.exit("Too many Command-line argument")
elif ".csv" not in (sys.argv[1] or sys.argv[2]):
        sys.exit("Not a csv file")
elif not os.path.exists(sys.argv[1]):
        sys.exit("File not found")

with open(sys.argv[1], "r") as file:
    reader = csv.DictReader(file)
    rows = []
    for row in reader:
        lname, fname = row["name"].split(", ")
        house = row["house"]
        rows.append({"firstname": fname, "lastname": lname, "house": house})

with open(sys.argv[2], "w", newline='') as file2:
    fieldnames = ["firstname", "lastname", "house"]
    writer = csv.DictWriter(file2, fieldnames=fieldnames)

    writer.writeheader()  # Write header only once

I still have this problem which I cannot solve :

:( scourgify.py cleans short CSV file scourgify.py does not produce CSV with specified format :| scourgify.py cleans long CSV file can't check until a frown turns upside down

Any could help identify and solve this error?

  • Why are you proceeding to advance weeks in the program when you still have outstanding questions from prior weeks, and presumably have not completed those weeks? Please mark your questions as answered if they have been answered or respond if the answer is not helpful.
    – UpAndAdam
    Commented Dec 12, 2023 at 22:33
  • I finished coding the previous ones but still have errors, i got the idea, thats why im moving forward. Thank you and i have answered the previous answers on my questions. Commented Dec 13, 2023 at 13:56
  • Thanks I saw that an am removing some of the corresponing comments. in general though you really need to make sure you learn the lessons of earlier problems.. You seem to be making the renaming things mistake in a couple of problems, though in your pizza.py example I'll admit that until I try it locally with your code I don't see a problem
    – UpAndAdam
    Commented Dec 13, 2023 at 15:38
  • Did lines.py get resolved? cs50.stackexchange.com/questions/44711/… similarly what about little professor?
    – UpAndAdam
    Commented Dec 13, 2023 at 15:39
  • Yes yes! I just marked them as completed! Thanks! Commented Dec 13, 2023 at 16:09

1 Answer 1


You are using incorrect keys for the columns in your output format. instead of firstname and lastname you need to use first and last respectively

You need to follow instructions carefully. Read the instructions for the exact specification of what they require you to do, and what the required output should look like.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .