Phạm Công Thành
New member
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.
Answer
Use the below steps to delete the first line from a file.
- Open file in a read and write mode ( r+ )
- Read all lines from a file.
- Move file pointer at the start of a file using the seek() method.
- Truncate the file.
- Write all lines from a file except the first line.