We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 77d851f commit e3ff48fCopy full SHA for e3ff48f
FluentPython/StrKeyDict1.py
@@ -0,0 +1,11 @@
1
+import collections
2
+class StrKeyDict(collections.UserDict):
3
+ def __missing__(self, key):
4
+ if isinstance(key,str):
5
+ raise KeyError(key)
6
+ return self[str(key)]
7
+ def __contains__(self, key):
8
+ return str(key) in self.date
9
+ def __setitem__(self, key, item):
10
+ print('setitem',item)
11
+ self.data[str(key)] = item
0 commit comments