python - Creating dictionaries with pre-defined keys -
In Python, there is a way to create a class that has been treated like a dictionary, but when the key is Is a pre-defined new example made?
You can easily expand any type of created type. This is how you do it with a dict:
gt; & Gt; Class Miklas (dict): ... def __init __ (self, * args, ** quorz): ... [[Mikey] = 'mew!' Itself ... ['Mikey 2'] = 'MyWhole 2 '.... & Gt; & Gt; & Gt; X = MyClass ()> & gt; & Gt; & Gt; X ['mykey'] 'myvalue' & gt; & Gt; & Gt; X {'mykey2': 'myvalue2', 'mykey': 'myvalue'} I could not find the Python document talking about it, but the very popular book Available online for free.
Comments
Post a Comment