Looping issues
Hamilton, William
whamil1 at entergy.com
Thu Apr 5 15:16:03 EDT 2007
-----Original Message-----
From: python-list-bounces+whamil1=entergy.com at python.org
[mailto:python-list-bounces+whamil1=entergy.com at python.org] On Behalf Of
brochu121 at gmail.com
Sent: Thursday, April 05, 2007 1:01 PM
To: python-list at python.org
Subject: Looping issues
What I am trying to do is compare two files to each other.
If the 2nd file contains the same line the first file contains, I want
to print it. I wrote up the following code:
correct_settings = open("C:\Python25\Scripts\Output
\correct_settings.txt","r")
current_settings = open("C:\Python25\Scripts\Output\output.txt","r")
for line in correct_settings:
for val in current_settings:
if val == line:
print line + " found."
correct_settings.close()
current_settings.close()
For some reason this only looks at the first line of the
correct_settings.txt file. Any ideas as to how i can loop through each
line of the correct_settings file instead of just looking at the first?
=====================================
I think the problem is that it's actually only looping through
current_settings once; for the remaining lines in correct_settings,
current_settings is at EOF and produces nothing to be matched.
for line in correct_settings:
if line in current_settings:
print line + "found."
This may do what you want.
---
-Bill Hamilton
whamil1 at entergy.com
More information about the Python-list
mailing list