I have a piece of code where I am trying to gain the user's input and delete the row of that specific line in the csv file. I have tired doing so with the code below but it deletes the row and header too. I want to just delete the row not the header, the problem is in the remove_a_team function. How can I fix this? Thank you.
import csv
import time
header_teams = ['TeamName', 'Member1', 'Member2', 'Member3', 'Member4', 'Member5']
#creating a header for the team's csv file.
with open('teams.csv', 'w', newline = '', encoding='UTF8') as f:
writer = csv.writer(f)
#writing the header for the csv file.
writer.writerow(header_teams)
f.close()
def add_a_team():
team_adder = []
name = str(input("You are now entering the data for a team.\nEnter the team's name."))
team_adder.append(name)
time.sleep(0.3)
name = str(input("Enter the first team member's name."))
team_adder.append(name)
time.sleep(0.3)
name = str(input("Enter the second team member's name."))
team_adder.append(name)
time.sleep(0.3)
name = str(input("Enter the third team member's name."))
team_adder.append(name)
time.sleep(0.3)
name = str(input("Enter the fourth team member's name."))
team_adder.append(name)
time.sleep(0.3)
name = str(input("Enter the fifth team member's name."))
team_adder.append(name)
time.sleep(0.3)
print("Team successfully added.")
print("\n")
with open('teams.csv', 'a', newline = '', encoding='UTF8') as f:
writer = csv.writer(f)
#writing the data for each team.
writer.writerow(team_adder)
f.close()
def remove_a_team():
content_team = input(str("What team would you like to remove?"))
with open('teams.csv', 'r', newline = '', encoding='UTF8') as f:
lines = f.readlines()
with open('teams.csv', 'w', newline = '', encoding='UTF8') as f:
for line in lines:
if line == content_team:
writer.writerow(row)
else:
print("That team does not exist")
f.close()
add_a_team()
remove_a_team()