我正在尝试获取用户输入并交叉引用,以查看它是否在文件中。但是,它只运行for循环一次;如果我在第一次运行时就正确了,如果第一次出错,它就永远不会运行,因为for循环只运行一次。当它为while循环重新运行时,它从不重新运行for循环。为什么python只允许您运行一次循环,我如何解决这个问题?这是密码testDate = open("Sales.txt")
python循环语法,def DateTest(Position):
validSyntax = False
Complete = False
DateIn = True
while Complete == False:
if DateIn == False:
print "That date is not in the file."
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 "That is invalid input."
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")
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态