Delete line of file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Delete line of file (/thread-28838.html) |
Delete line of file - dionatandiego11 - Aug-05-2020 Hi, I would like to create a function that when triggered deletes line from a txt file ex: a = input ("which movie would you like to delete?") a = Donnie Darko print ("+ a, successfully deleted!")Help, please RE: Delete line of file - DPaul - Aug-05-2020 For starters: 1. The resulting input variable will be a string -> line 2 -> 'Donnie Darko' is the value of a, so line 2 is superfluous 2. print ("+ a, successfully deleted!") -> is +a somehow the variable a , you want to print ? 3. The part of the code where you read the txt file is missing, pls add it. Paul RE: Delete line of file - deanhystad - Aug-05-2020 You can read files and write files and append to files. You can replace in files, but it is so limited and error prone that it should not be attempted. You cannot remove something from a file. Now that you know you cannot delete something from a file, how are you going to solve your problem? As a hint the only file operations you need are open, close, read and write. |