输入年月日,获得下个月的同一天,如果该天不存在,则顺延一天
作者:互联网
def victory_look_date(self,filePath,sheet,startYear,startMonth,startDay): self.tmp = self.readExl(filePath, sheet) # 调用读取源数据(excell表格中记录的数据),将日期和收盘价存入字典中 self.dateData = None # 创建一个变量来接收敲出观察日 self.month = startMonth m = 0 n = 0 k = 1 self.day =startDay while True: try: if self.month == 12: self.dateData = datetime.date(startYear, 1, self.day+m) if self.dateData not in list(self.tmp.keys()): m += 1 else: break else: try: self.dateData = datetime.date(startYear, startMonth+k, self.day+n) if self.dateData in list(self.tmp.keys()): break else: if startDay + n == 31: self.day = 1 n = 0 k += 1 else: n += 1 except: k += 1 self.day = 1 n = 0 self.dateData = datetime.date(startYear, startMonth + k, self.day + n) self.month = self.dateData.month except: pass
标签:该天,startYear,self,startMonth,day,年月日,month,dateData,顺延 来源: https://blog.csdn.net/wwenww/article/details/122622424