Good day pythonians,
I want to make a custom dictionary with two main features:
- All keys are declared on creation
- It is impossible to add new keys or modify current ones (values are still modifiable)
Right now code is this:
class pick(dict):
"""This will make delicious toffee when finished"""
def __init__(self, *args):
dict.__init__(self)
for arg in args:
self[arg] = None
Any help is much appreciated.
upd:
While solution is what I was looking for there is one problem:
dictionary calls the __setitem__
to add the items on the initialization and not finding the keys it raises the error.
cupboard = pick('milk') #raises error
upd1:
all solved, thank you very much.