[Tutor] FrozenDict

Albert-Jan Roskam sjeik_appie at hotmail.com
Wed Oct 7 18:10:20 CEST 2015


Hi,
I wanted to create a read-only dict to hold some constants. I looked around on the internet and created two implementations:-FrozenDict (derives from collections.mapping)-ChillyDict (derives from dict, which seems more obvious to me)
The code can be found here: http://pastebin.com/QJ3V2mSK
Some questions:1. one doctest from FrozenDict fails: fd.keys() returns an empty list. Why?2. Is FrozenDict the way to use collections.mapping (aside from the error!). I just discovered this and i seems quite cool (pun intended)3. Which implementation is better, and why? I like ChillyDict better because it is more straightforward and shorter.
The read-only dict does not need to be very fast, it just needs to give some reasonable protection against mutating values.It also needs to work under Python 2.7 and 3.3+.
Thank you!
Albert-Jan


 		 	   		  


More information about the Tutor mailing list