I wrote the following script
#! /usr/bin/python
import glob
path = raw_input('In which dir do you want to look for the files?')
path += '/*.txt'
files=glob.glob(path)
for seq in files:
f=open(seq)
total = 0
for line in f:
if 'NAR' in line:
print("bum")
f.close()
So if I have a file like this:
NAR 56 rob
NAR 0-0 co
FOR 56 gs
FRI 69 ds
NIR 87 sdh
I would expect my code to print
bum bum
Then I tried the following after reading here
#! /usr/bin/python
import glob
path = raw_input('In which dir do you want to look for the files?')
files=glob.glob(path)
for seq in files:
with open(seq) as input_file:
for line in input_file:
if 'NAR' in line:
print("bum")
input_file.close()
but both do not work. What I am doing wrong here?