'port' 'host''localhost''username'none'password'none'debug'falsedef __init__(self**kwargs)self options dict(options default_optionsself options update(kwargsdef __getitem__(selfkey)return self options[keyall the interesting stuff in this class happens in the __init__ method we have dictionary of default options and values at the class level the first thing the __init__ method does is make copy of this dictionary we do that instead of modifying the dictionary directly in case we instantiate two separate sets of options (rememberclass-level variables are shared between instances of the class then__init__ uses the update method on the new dictionary to change any non-default values to those supplied as keyword arguments the __getitem__ method simply allows us to use the new class using indexing syntax here' session demonstrating the class in actionoptions options(username="dusty"password="drowssap"debug=trueoptions['debug'true options['port' options['username''dustywe're able to access our options instance using dictionary indexing syntaxand the dictionary includes both default values and the ones we set using keyword arguments the keyword argument syntax can be dangerousas it may break the "explicit is better than implicitrule in the preceding exampleit' possible to pass arbitrary keyword arguments to the options initializer to represent options that don' exist in the default dictionary this may not be bad thingdepending on the purpose of the classbut it makes it hard for someone using the class to discover what valid options are available it also makes it easy to enter confusing typo ("debuginstead of "debug"for examplethat adds two options where only one should have existed