I am trying to get user input and cross-reference it to see if it is in a file. However, it only runs the for loop once; if I get it right the first time it works, if I get it wrong the first time then it never does because the for loop only runs once. When it re-runs for the while loop it never re-runs the for loop. Why does python only allow you to run loop once, and how do I fix this? Here is the code,
testDate = open("Sales.txt")
def DateTest(Position):
validSyntax = False
Complete = False
DateIn = True
while Complete == False:
if DateIn == False:
print
print "That date is not in the file."
print
Date = raw_input("Please input the desired %s date in the form YYYY,MM,DD: " % Position)
try :
Date = Date.strip().split(',')
Year = int(Date[0])
Month = int(Date[1])
Day = int(Date[2])
Date = (Year, Month, Day)
except:
print
print "That is invalid input."
print
else:
validSyntax = True
if validSyntax == True:
#It only runs this once, if I put a debug statement after the 'for' #then it never prints out, the loop never runs after the first time
for line in testDate:
line = line.strip().split(',')
yearTest = int(line[0])
monthTest = int(line[1])
dayTest = int(line[2])
dateTest = (yearTest, monthTest, dayTest)
if Date == dateTest:
Complete = True
print 'success'
DateIn = False
validSyntax = False
Response = DateTest("start")