Reputation: 575
import os
import fileinput
filenames1=os.listdir("./chi_square_metal_region_1")
filenames1.sort()
for line in fileinput.input("./test_input.dat"):
for eachfile in filenames1:
if eachfile == line:
print yes
I don't get any errors when I run this code, but it's not printing 'yes', which is the expected output.
It should print 'yes' twice as I there are two files in input which match with eachfile
. Why is it not printing the expected output?
Upvotes: -1
Views: 185
Reputation: 3773
The problem is that:
for line in fileinput.input("./test_input.dat"):
the variable line will contain '\n' at the end. Try this:
import os
import fileinput
filenames1=os.listdir("./chi_square_metal_region_1")
filenames1.sort()
for line in fileinput.input("./test_input.dat"):
for eachfile in filenames1:
if eachfile == line[:-1]:
print yes
Upvotes: 1