class documentation

class TypeConversionDict(dict):

Known subclasses: werkzeug.datastructures.ImmutableTypeConversionDict, werkzeug.datastructures.MultiDict

View In Hierarchy

Works like a regular dict but the get method can perform type conversions. MultiDict and CombinedMultiDict are subclasses of this class and provide the same feature.

New in version 0.5.
Method get No summary
def get(self, key, default=None, type=None):

Return the default value if the requested data doesn't exist. If type is provided and is a callable it should convert the value, return it or raise a ValueError if that is not possible. In this case the function will return the default as if the value was not found:

>>> d = TypeConversionDict(foo='42', bar='blub')
>>> d.get('foo', type=int)
42
>>> d.get('bar', -1, type=int)
-1
Parameters
keyThe key to be looked up.
defaultThe default value to be returned if the key can't be looked up. If not further specified None is returned.
typeA callable that is used to cast the value in the MultiDict. If a ValueError is raised by this callable the default value is returned.