Hi there, Im trying to search a file where the the line containing the search term is found and printed along with a number of lines before and after the search term defined by the user. The coding i have so far is:
f = open(f, 'r')
d = {}
for n, line in enumerate(f):
d[n%numb] = line.rstrip()
if search_term in line:
for i in rang(n+1,n+1+numb):
print d[i%numb]
for i in range(1, numb):
print f.next().rstrip()
But i get a TypeError at d[%numb] = line.rstrip() Unsupported operand type(s) for %: 'int' and 'str'
Help would be great thanks