Difference Python on Windows & Linux: datetime.datetime object has no attribute total_seconds

  datetime, linux, python, windows

A python script I developed in Linux works fine in Linux. It uses openpyxl to iterate over cells in an Excel-file, compares values to lists, and calculates total time spent by adding different timedelta objects (in total seconds). So far so good…

But the script does not work on my Windows laptop I use for work. Installed is Python 3.8.5. The error I get is:

File "Worktypes", line 54, in <module>
    ndcluren += int(f.total_seconds())
AttributeError: 'datetime.datetime' object has no attribute 'total_seconds

The original code in the script is:

for j in range(6):
    facturen = 0
    decluren = 0
    ndcluren = 0
    resturen = 0
    for i in range(5,30):
        e = sheet2.cell(row = i, column = 1).value
        f = sheet2.cell(row = i, column = j+5).value
        if f:
            if e in fact:
                facturen += int(f.total_seconds())
            elif e in decl:
                decluren += int(f.total_seconds())
            elif e in ndcl:
                ndcluren += int(f.total_seconds())
                resturen += int(f.total_seconds())
    sheet4.cell(row = 2, column = j+3).value = facturen / 3600
    sheet4.cell(row = 3, column = j+3).value = decluren / 3600
    sheet4.cell(row = 4, column = j+3).value = ndcluren / 3600
    sheet4.cell(row = 5, column = j+3).value = resturen / 3600

What is somewhat surprising is that the script handles total_seconds() fine for the "facturen" and the "decluren", but then fails for the ndcluren. This makes me think that the error is in the excel spreadsheet. But I cannot find anything strange or special. Changing the cell formatting also doesn’t work.

I already spent quite some hours on this. Indications from Google indicate that the script uses python2 instead of python3. But also after forcing python3 I get this error on Windows.

Source: Windows Questions