def d_avatar(): filePath = "data.csv" with open(filePath) as csvfile: reader = csv.DictReader(csvfile) filePath = "sample_write_data.csv" with open(filePath,'w',newline='') as csvfile: fieldnames = ['name','tribe','id','Air','Water','Earth','Fire'] writer = csv.DictWriter(csvfile,fieldnames=fieldnames) print("Delete an avatar") deletion = input("Enter avatar id to delete: ") for row in reader: if deletion != row['id']: print("avatar ID is not found") deletion = input("Enter avatar id to delete: ") else: if deletion == row['id' ]: writer.writerow(row) ; print("Avatar Record Deleted")
for row in reader: if deletion != row['id']: writer.writerow(row) ; # write all non-matching rows else: print("Avatar Record Deleted") # nothing to write
=
==
!=
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)