2017-04-21 33 views
0
def optionFour(self): 
if self == 4: 

    inFile = open('dates.csv', 'r') 

    for line in inFile: 
     gFile = line.strip() 
     gFile = gFile.split(',') 

     occurence = gFile[0] 
     month = int(gFile[1]) 
     day = int(gFile[2]) 
     year = int(gFile[3]) 
     time = gFile[4] 
     event = gFile[5] 
     dates = [month, day, year] 


     day5 = int(input('Enter a day:')) 
     month5 = int(input('Enter a month:')) 
     year5 = int(input('Enter a year:')) 
     dateSelected = [month5, day5, year5] 
     if dates == dateSelected: 
      return str((occurence, ' appointment starting on (', dateSelected, '): ', time, ', ', event)) 
     else: 
      return str('Nothing') 
      break 

    inFile.close() 

它只是通过输入文件的第一行,为什么它可以这样做呢?它只是检查第一行,没有别的。只能通过输入文件的第一行

+1

'return'使函数...'return',你应该不想使用'continue'吗? –

+0

是的,正如Pedro Lobito所说。我不会投下这个问题,但请删除它。在提问之前请检查您的代码流程。 –

+0

第一次迭代你的函数进入'return'。 'return'后你将退出功能 – Sklert

回答

0

您的代码只读取一行,因为这就是您要求它执行的操作:读取一行,从用户处获取日期,并比较两者。如果他们匹配,则返回预约;如果它们不匹配,则返回“Nothing”。

注意,你不能去要么休息声明或文件关闭:您回报逼出来的函数的流量你到达那里之前。

我怀疑你需要的是阅读行的所有,存储信息,并然后要求用户输入一个日期在该存储找到。