How to search for a text in file and print the related lines in Python

1 Answer

0 votes
search_text = ' Python '
with open('d:\data.txt', mode='r') as file:
    for line in file:
        if search_text in line:
            print(line)

'''
run:

Profession: Python Programmer

Profession: Python , Java and PHP Programmer

'''

 



answered Sep 26, 2017 by avibootz

Related questions

...