Did I find the right examples for you? yes no

All Samples(4)  |  Call(4)  |  Derive(0)  |  Import(0)
Produce a dictionary of an object's attributes. Builds on dir2 by
checking that a getattr() call actually succeeds.

        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
        


src/i/p/ipython-HEAD/IPython/utils/tests/test_wildcard.py   ipython(Download)
 
        a = A()
        adict = wildcard.dict_dir(a)
        assert "a" not in adict # change to assertNotIn method in >= 2.7
        self.assertEqual(adict["b"], 2)

src/a/n/antisocial-HEAD/ve/lib/python2.7/site-packages/IPython/utils/tests/test_wildcard.py   antisocial(Download)
 
        a = A()
        adict = wildcard.dict_dir(a)
        assert "a" not in adict # change to assertNotIn method in >= 2.7
        self.assertEqual(adict["b"], 2)

src/i/p/ipython-py3k-HEAD/IPython/utils/tests/test_wildcard.py   ipython-py3k(Download)
 
        a = A()
        adict = wildcard.dict_dir(a)
        assert "a" not in adict # change to assertNotIn method in >= 2.7
        self.assertEqual(adict["b"], 2)

src/i/p/ipython-2.0.0/IPython/utils/tests/test_wildcard.py   ipython(Download)
 
        a = A()
        adict = wildcard.dict_dir(a)
        assert "a" not in adict # change to assertNotIn method in >= 2.7
        self.assertEqual(adict["b"], 2)