I am trying to insert a date object in a list. But, on execution, the code raises a TypeError. Here's the code:
values.append(datetime.date(tuple(checkIn)))
values.append(datetime.date(tuple(checkOut)))
For viewing pleasure, I provided only the lines that raises the error.
Here,
values
is a listcheckIn
and checkOut
are lists. eg- checkIn = [2020, 11, 28]
This is the error message:
File "d:/coding/python/hms.py", line 195, in booking
values.append(dt.date(tuple(checkIn)))
TypeError: an integer is required (got type tuple)
So, why can't I insert tuple into a list?
You need to unpack checkIn
and checkOut
in order to pass the values as arguments:
import datetime as dt
values = []
checkIn = [2020, 11, 28]
values.append(dt.date(*checkIn))
print(values)
Out:
[datetime.date(2020, 11, 28)]