Why can't I use a date as a key for a dictionary?

Create a table with a date column, get a row from the table, create a dictionary and use the date as a key, and you get 'AttributeError: 'date' object has no attribute '_getstate'

row = app_tables.stuff.get(name='joe')
d = {}
d[row[date]] = 'xxx'

I think you may have to change the date to a str for it to be a key :

d[str(row[date])] = 'xxx'

or possibly, depending on how you read it :

d[row[str(date)]] = 'xxx'

Don’t know why using a date directly doesn’t, though.

All datetime objects are immutable. The following code works in Python:

import datetime
dic={datetime.datetime.now(): 'hello'}

but doesn’t work in Anvil.

1 Like

the situation seems to be the same at this very moment

This works server side in Anvil, but not client side.

I guess it’s not implemented in Skulpt yet; do remember client side python is V3-ish, with some things either not implemented yet or just not possible.