Delete a row from a text file with Python

前端 未结 5 1929
说谎
说谎 2020-12-19 15:43

I have a file where each line starts with a number. The user can delete a row by typing in the number of the row the user would like to delete.

The issue I\'m having

5条回答
  •  天涯浪人
    2020-12-19 16:30

    Instead of writing out all lines one by one to the file, delete the line from memory (to which you read the file using readlines()) and then write the memory back to disk in one shot. That way you will get the result you want, and you won't have to clog the I/O.

提交回复
热议问题