Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

searching through a file in python

# Open the file
fhand = open('path and the name of the file')
count = 0
# iterate through the lines in the file
for line in fhand:
    # Remove the 
 at the end and stop printing an empty line
    line = line.rstrip()
    if 'sub string' in line:
        count += 1
        print(count, line)
# Close the file
fhand.close()
Source by www.py4e.com #
 
PREVIOUS NEXT
Tagged: #searching #file #python
ADD COMMENT
Topic
Name
1+1 =