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

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -