count = 0
with open('Test.csv', encoding='iso-8859-1') as file:
for line in file:
if "K,K,K,K" in line:
count = 1
print(count)
The output:11 Im looking to get the whole line out Example into the file 06/03/2021,3,K,K,K,K 12/04/2021,29,9,A,8,9 16/03/2019,7,Q,8,9,8 26/02/2020,50,K,K,K,K
CodePudding user response:
if you want to print the line, then instead of count =1
, add print(line)
.
CodePudding user response:
This starts with an empty list and then any matches are stored in the list as they are found, then you can re-use the list any time in the rest of your code.
count = 0
k_matches=[]
with open('Test.csv', encoding='iso-8859-1') as file:
for line in file:
line = line.strip('\n')
if "K,K,K,K" in line:
k_matches.append(line)
count =1
print(k_matches)
Output of print
['06/03/2021,3,K,K,K,K', '26/02/2020,50,K,K,K,K']