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
writer.writerows(rows)
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?