I want to see if a certain word is in a text file, how do I go about that?

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()

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!

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.