-2

I am trying to figure out how to convert a file.txt into a string so I can use the find() operation to find certain text in a .txt file. Does anyone know how to convert a .txt file into a string using python 3?

First Time Asking A Question On Stack Overflow

-Sorry if it’s bad

1 Answers1

1
with open('file.txt', 'r') as thefile:
    string = thefile.read()

You can refer to the Python docs on File I/O or other tutorials as well for more info on this.

gdcodes
  • 266
  • 2
  • 10