-3

I thought it might look like this but I am unsure:

example = open("example.txt","r")

if example #has text1 in it then#: <-- What do I need to put between the #'s for the code to work?

  • 1
    You have a good start by opening the file. It might help to do some other related exercises first. For example, figure out how to print each line from the file to the screen. This will help you understand some things that will get you closer to solving the problem. – Code-Apprentice Mar 02 '21 at 19:20
  • 2
    Does this answer your question? [How to search for a string in text files?](https://stackoverflow.com/questions/4940032/how-to-search-for-a-string-in-text-files) – Hunter Bertoson Mar 02 '21 at 19:22

1 Answers1

-1
import re
wordChk = re.compile(r'(.*)?text1(.*)?')
fileName=open("d:/foo.bar")
lines = [i for i in fileName.readlines()]
for x in lines:
    if wordChk.match(x):
        do something
Kyle Hurst
  • 252
  • 2
  • 6