Lets say I am trying to find a spesific string in a txt file in python and I want to get that line how do I do it?
Finding a spesific string and getting its line in PYTHON 3.X
46 views Asked by Ömer Kural At
1
Lets say I am trying to find a spesific string in a txt file in python and I want to get that line how do I do it?
Say your file is called
file.txt
, you can usenext()
on a generator expression which yields the indexes of lines in the file containingyour_string
. To be able to work with the indexes and the contents, we can useenumerate()
: