答案 0 :(得分:1)
怎么样:
test3.txt
Alex
Foo
Bar
Alex
Spam
test.py
#!/usr/bin/python
searching_for = raw_input('Looking for: ')
with open('test3.txt') as file:
lines = file.read().splitlines()
for i in range(0, len(lines)):
if(lines[i] == searching_for):
print 'Found something: ' + lines[i]