The Quantum Garden

Life learning, for life

Buy me a coffee
David C. Buchan
Bendigo
Victoria
Australia
Business Technology Consultant
Home

❯

Notes

Delete single line from file using Python

4 June 2024

How to delete a line in text file using Python | Website Scripts And Cloud Tutorials (mistonline.in)

#!/usr/bin/python
def deleteLine():
 fn = 'myfile'
 f = open(fn)
 output = []
 str="The"
 for line in f:
   if not line.startswith(str):
    output.append(line)
 f.close()
 f = open(fn, 'w')
 f.writelines(output)
 f.close()
deleteLine()


Recent Blogs

  • Unsustainable shame

    23 June 2026

  • Now, 21 June 2026

    21 June 2026

  • The cost of saying no, then doing it anyway

    12 June 2026

  • The human side of digital literacy

    5 June 2026

  • Migrating from Quartz 4 to Quartz 5

    29 May 2026

See 570 more →

Graph View


  • Subscribe
  • About
  • |
  • Privacy
  • AI Policy
  • |
  • Mastodon
  • Github
© David C. Buchan 2002–2026. Last update: 23 June 2026 at 7:50 pm. Recently updated notes.
1433 site pages. Colophon. total unique visits.