Hi, I´m trying to read from a file, and then see if 2 Lines in there are equal if so then break the while loop. I cant recive the information from line2. In other words if line1==line2. In anywhere in the file.
example: line1 = [0,2,3,5,6], line2=[0,2,3,5,6]
I have used the readin code in a another file, and works like a charm. But not in here don´t know why. Please guys help me out.
while gameSet <26:
cardList.sort()
cardList = [card for card in cardList if card];
for i in range(len(cardList)):
cardList.sort();
cardList[i]-=1;
newHeap = len(cardList);
cardList.append(newHeap);
print gameSet, ": cardList in loop: ", cardList;
forfile = str(cardList);
#Put output to file
fileName = "file13.txt";
inFile = open(fileName, "a")
for i in range(1):
add = (str(forfile)+"\n");
inFile.write(str(add));
inFile.close();
#Read file and compare
inFile=open(fileName)
while True:
line1 = inFile.readline()
line2 = inFile.readline()
if not line2: break
print "line1: ",line1,"line2: ",line2
if (line1==line2) & (line1!="") & (line2!="") :
break
inFile.close;
gameSet +=1;
This is the output:
Game starts with this:[5.0, 5.0]
1 : cardList in loop: [4.0, 4.0, 2]
line1: [4.0, 4.0, 2]
line2:
2 : cardList in loop: [1, 3.0, 3.0, 3]
line1: line2:
3 : cardList in loop: [0, 2.0, 2.0, 2, 4]
line1: [0, 2.0, 2.0, 2, 4]
line2:
4 : cardList in loop: [1.0, 1.0, 1, 3, 4]
line1: line2:
5 : cardList in loop: [0.0, 0.0, 0, 2, 3, 5]
line1: [0.0, 0.0, 0, 2, 3, 5]
line2:
6 : cardList in loop: [1, 2, 4, 3]
line1: line2:
7 : cardList in loop: [0, 1, 2, 3, 4]
line1: [0, 1, 2, 3, 4]
line2:
8 : cardList in loop: [0, 1, 2, 3, 4]
line1: line2:
9 : cardList in loop: [0, 1, 2, 3, 4]
line1: [0, 1, 2, 3, 4]
line2:
cardList: [0, 1, 2, 3, 4]