python dictmixin object with property decorator
Question: I was instructed to use more pythonish way of setter and getters @property. So
we have something like this:

    
    
    from UserDict import DictMixin
    
    class A(dict):
        def __init__(self, a, b):
            self.a = a
            self.b = b
    
        @property
        def a(self):
            return self._a
    
        @a.setter
        def a(self, value):
            self._a = value
    
        def __getitem__(self, key):
            return getattr(self, key)
    
        def __setitem__(self, key, value):
            setattr(self, key, value)
    
        def keys(self):
            return [k for k in self.__dict__.keys() if not k.startswith('_')]
    
        def do_whatever(self):
            pass
    
    
    a = A(1,2)
    print a.keys()
    

output is ['b'] and at first I wasn't expecting that, but it actually makes
sense.

Question is how to get all properties names but not names of methods. Any
ideas?


Answer: Properties are implemented as
[descriptors](http://docs.python.org/2/reference/datamodel.html#descriptors),
and so belong to the _class_ , not the _instance_ :

    
    
    >>> class Question(object):
    ...     @property
    ...     def answer(self):
    ...         return 7 * 6
    ... 
    >>> q = Question()
    >>> q.answer
    42
    >>> q.__dict__
    {}
    >>> for key, value in Question.__dict__.iteritems():
    ...     if isinstance(value, property):
    ...         print key
    ...
    answer
    

