Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Handling a .txt text
#1
Hi, Folks! I'm trying to open a .txt file and find a line with a specific expression but the return isn't what I expected:

 f = open("file.txt", "r")

 for line in f: 
   
       if "Net" in line: 
       
           print(line)
       else:
           print("Didn't find")

 f.close()
So, what i get is a lot of "Didn't find" but I know that there's this expression in the file. And, I noticed that if i ask for just one caracter, like "N" instead the "Net", the code returns lines with it.
Reply


Messages In This Thread
Handling a .txt text - by reinalazaro - Jan-09-2020, 01:27 AM
RE: Handling a .txt text - by ichabod801 - Jan-09-2020, 03:18 AM
RE: Handling a .txt text - by Clunk_Head - Jan-09-2020, 03:24 AM
RE: Handling a .txt text - by sandeep_ganga - Jan-09-2020, 03:26 AM
RE: Handling a .txt text - by perfringo - Jan-09-2020, 11:09 AM
RE: Handling a .txt text - by reinalazaro - Jan-11-2020, 01:59 AM
RE: Handling a .txt text - by Clunk_Head - Jan-11-2020, 02:16 AM
RE: Handling a .txt text - by reinalazaro - Jan-11-2020, 09:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Star python exception handling handling .... with traceback mg24 3 1,287 Nov-09-2022, 07:29 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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