How do you delete a specific line in a file using Python?

How do you delete a specific line in a file using Python?
Answer
Use the below steps to delete the first line from a file.
  1. Open file in a read and write mode ( r+ )
  2. Read all lines from a file.
  3. Move file pointer at the start of a file using the seek() method.
  4. Truncate the file.
  5. Write all lines from a file except the first line.
 

Tìm kiếm

Back
Top