将第54周设为python的第01周

问题描述 投票:0回答:1

因此,我受过教育,因此出于某种奇怪的原因,我将周标记为完全不正确的...直到第53周的所有工作都很好,但由于某些原因,他们决定第54周也存在,现在我的代码崩溃了(课程)

因此,我需要一些代码,告诉我的代码,第54周实际上是第01周,第55周是第02周,第56周是第03周,依此类推。我的想法是,但不确定如何继续进行以下工作:

if week >= 54:
   something should happen here
def BuildTimeTable(Days):
    #print(Days)
    TimeTable = []
    for i in range(len(Days)):
        for j in range(len(Days[i])):
            for k in range(len(Days[i][j])):
                day = Days[i][j].get("Dag")[k]
                start = Days[i][j].get("Begintijd")[k]
                end = Days[i][j].get("Eindtijd")[k]
                desc = Days[i][j].get("Activiteit")[k]
                room = Days[i][j].get("Locatie")[k]
                staff = Days[i][j].get("Docent")[k]
                dates = Days[i][j].get("Weken")[k]
                year = "2019"
                week = str(dates-1)
                print(week)
                print(dates)
                year_week_day = year + "-" + week + "-" + str(day)
                result_date = str(datetime.datetime.strptime(year_week_day, "%Y-%W-%A").date())
                AddTimeTableEvent(TimeTable, day, start, end, desc, room, staff, result_date)
    #print(TimeTable)
    return TimeTable

我现在得到的错误是:

Traceback (most recent call last):
  File "swscust2ics.py", line 219, in <module>
    TimeTable = BuildTimeTable(Days)
  File "swscust2ics.py", line 139, in BuildTimeTable
    result_date = str(datetime.datetime.strptime(year_week_day, "%Y-%W-%A").date())
  File "/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_strptime.py", line 332, in _strptime
    (data_string, format))
ValueError: time data '2019-54-maandag' does not match format '%Y-%W-%A'
python datetime python-datetime strptime
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.