Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to test if a value is or is like a dictionary
#1
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?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#2
collections.abc.MutableMapping

Output:
>>> import os >>> import collections.abc >>> isinstance(os.environ, collections.abc.MutableMapping) True >>> isinstance({}, collections.abc.MutableMapping) True
Skaperen and buran like this post
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Test Case Assertion Error moga2003 10 273 Mar-18-2019, 01:06 AM
Last Post: moga2003
  test pattern and add result in a table sam1975 1 79 Mar-05-2019, 02:41 PM
Last Post: sam1975
  new python package test ramkrishna 0 63 Feb-25-2019, 12:18 PM
Last Post: ramkrishna
  How to make loop go back to the beginning if test evaluaes to True. FWendeburg 1 112 Feb-13-2019, 01:26 AM
Last Post: stullis
  unit test roll die saladgg 5 533 Nov-06-2018, 11:39 PM
Last Post: stullis
  Having issues getting a multiple choice test program to work Py_JohnS 2 371 Sep-01-2018, 11:06 PM
Last Post: Py_JohnS
  Mix-in class tree file not running the self test code. arjunsingh2908 3 424 Aug-14-2018, 05:46 PM
Last Post: arjunsingh2908
  pytest fixture in conftest.py thrown error while in the test file runs OzzieOzzum 1 371 Jul-31-2018, 12:12 PM
Last Post: OzzieOzzum
  code pattern to test if list has all the same Skaperen 5 555 Jul-25-2018, 06:09 AM
Last Post: buran
  Problem test picalex06 3 557 Jun-27-2018, 09:10 PM
Last Post: woooee

Forum Jump:


Users browsing this thread: 1 Guest(s)