这段代码每次都返回不在文件中的日期,我不知道为什么。
testDate = open("Sales.txt")
#Declaring variables for later in the program
printNum = 1
newcost = 0
startTestLoop = 1
endTestLoop = 1
#Creating a loop in case input is invalid
while startTestLoop > 0:
#Asking user for start date
#startDate = raw_input("Please input the desired start date in the form YYYY,MM,DD: ")
#Checking if input is valid, and arranging it to be used later
try :
startDate = startDate.strip().split(',')
startYear = startDate[0]
startMonth = startDate[1]
startDay = startDate[2]
startYear = int(startYear)
startMonth = int(startMonth)
startDay = int(startDay)
startDate = date(startYear, startMonth, startDay)
#Informing user of invalid input
except:
"That is invalid input."
print
#EndTry
#Testing to see if date is in the file, and informing user
if startDate not in testDate:
print "That date is not in the file."
#Exiting out of loop if data is fine
else:
startTestLoop -= 1
print "Aokay"
#EndIf