Find a word in a file

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Find a word in a file

 
0
  #1
Feb 19th, 2007
I want to see if a certain word is in a text file, how do I go about that?
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 148
Reputation: ghostdog74 is on a distinguished road 
Solved Threads: 40
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: Find a word in a file

 
0
  #2
Feb 19th, 2007
Originally Posted by sneekula View Post
I want to see if a certain word is in a text file, how do I go about that?
you can read in line by line
  1. for line in open("file"):
  2. if "word" in line:
  3. do_something(line)

you can read in one whole chunk
  1. data = open("file").read()
  2. if "someword" in data:
  3. do_something()
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Find a word in a file

 
0
  #3
Feb 20th, 2007
Holy smokes, ghostdog, you make it look real simple! Looks like Python really has the power of simplicity and elegance! Besides, I can actually understand the code as I read it!
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 18
Reputation: sharma_vivek82 is an unknown quantity at this point 
Solved Threads: 0
sharma_vivek82 sharma_vivek82 is offline Offline
Newbie Poster

Re: Find a word in a file

 
0
  #4
Apr 11th, 2007
for better maching of word , go through re module of python, you must find some interesting thing there..
Best wishes,
Vivek Sharma
Zope/Python Developer
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC