3
Contributors
3
Replies
8
Views
10 Years
Discussion Span
Last Post by sharma_vivek82
0

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

for line in open("file"):
   if "word" in line:
      do_something(line)

you can read in one whole chunk

data = open("file").read()
if "someword" in data:
    do_something()
0

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!

0

for better maching of word , go through re module of python, you must find some interesting thing there..
:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.