Python Forum
Basic Python 3 Win 10 Search Txt to File Newbie
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Python 3 Win 10 Search Txt to File Newbie
#5
Can write it it like this.
match = 'VisaRen'
with open('lines.txt') as f,open('new.txt', 'w') as f_out:
    for line in f:
        if match in line:
            f_out.write(line)
(Apr-18-2019, 09:05 PM)SnakeTyro Wrote: However, is there a simpler "Line Input, Write" routine until the end of file ("While Not EOF")?
Python always read to EOF,if not stop it in anyway.
So for line in f: read one line(memory effective) at time to EOF.
Reply


Messages In This Thread
RE: Basic Python 3 Win 10 Search Txt to File Newbie - by snippsat - Apr-18-2019, 09:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  very newbie problem on text file zapad 2 322 Apr-12-2024, 06:50 PM
Last Post: zapad
  Basic binary search algorithm - using a while loop Drone4four 1 443 Jan-22-2024, 06:34 PM
Last Post: deanhystad
  Search Excel File with a list of values huzzug 4 1,331 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Search for multiple unknown 3 (2) Byte combinations in a file. lastyle 7 1,477 Aug-14-2023, 02:28 AM
Last Post: deanhystad
  search file by regex SamLiu 1 962 Feb-23-2023, 01:19 PM
Last Post: deanhystad
  If function is false search next file mattbatt84 2 1,210 Sep-04-2022, 01:56 PM
Last Post: deanhystad
  Python newbie laleebee 2 1,389 May-24-2022, 01:39 PM
Last Post: laleebee
  fuzzywuzzy search string in text file marfer 9 4,734 Aug-03-2021, 02:41 AM
Last Post: deanhystad
  Cloning a directory and using a .CSV file as a reference to search and replace bg25lam 2 2,197 May-31-2021, 07:00 AM
Last Post: bowlofred
  Newbie on Python syntax rud0lp20 6 3,034 Apr-21-2020, 04:26 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020