File handling in python | Sololearn: Learn to code for FREE!

+1

File handling in python

I want to input a name that is already in a file and when it is inputed it deletes the name from the file

6/29/2022 7:08:43 PM

Uwalaka Ugochukwu

9 Answers

New Answer

+2

You may want to brush up on your syntax. name = input() with open(<file>) as names: name_list = names.readlines() if name in name_list: index = 0 for n in range(len(name_list)): if name_list[index] == name: name_list.pop(index) with open(<file>, w) as file: file.writelines(name_list)

0

That depends on how the names are written to the file. Provide examples and your attempt

0

Create a file with a list of patients awaiting organ donation, write a program where i can enter a patient's name and if the patient exists delete the patient's name from the file but if the patient doesn't exist add it to the file.

0

Okay, so lets see your attempt at that

0

Name=input() X=open(‘txt’, ‘w+’) X.write(the names goes here) Line=x.read() For lines in line: If line == name: Line.remove() Else: X.write(name)

0

We have to write in the file the list before this

0

a=open(‘filename.txt’, ‘w+’) a.write(the names goes here) Line=a.read()

0

Create a file with a list of patients awaiting organ donation, write a program where i can enter a patient's name and if the patient exists delete the patient's name from the file but if the patient doesn't exist add it to the file.

0

This is the question