输入年月日,获得下个月的同一天,如果该天不存在,则顺延一天

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

 

上一篇:Linux下简单几步安装AI开发环境-ROS(超有意思)


下一篇:(已解决2019.8.8)Background on this error at: http://sqlalche.me/e/e3q8