Python Forum

Full Version: how to test if a value is or is like a dictionary
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i have a function that needs to test if a value given to it in an argument is a dictionary or not. doing isinstance(thevalue,dict) is not good enough when the value comes from os.environ. but i would want the test to be positive for os.environ and anything like it as well as any genuine dictionary. what kind of test would work?
collections.abc.MutableMapping

Output:
>>> import os >>> import collections.abc >>> isinstance(os.environ, collections.abc.MutableMapping) True >>> isinstance({}, collections.abc.MutableMapping) True