code: def dict_dir(obj):
      """Produce a dictionary of an object's attributes. Builds on dir2 by
      checking that a getattr() call actually succeeds."""
      ns = {}
      for key in dir2(obj):
          # This seemingly unnecessary try/except is actually needed
          # because there is code out there with metaclasses that
          # create 'write only' attributes, where a getattr() call
          # will fail even if the attribute appears listed in the
          # object's dictionary.  Properties can actually do the same
          # thing.  In particular, Traits use this pattern
          try:
              ns[key] = getattr(obj, key)
          except AttributeError:
              pass
      return ns
  
file_path: catboost/contrib/python/ipython/py2/IPython/utils/wildcard.py
imports: import re
  import types
  from IPython.utils.dir2 import dir2
  from .py3compat import iteritems
label_desc: Use image node_id 4 for calling a global function with example usage: dict_dir(obj) and returns: ns