title: How to make class callable members iterable?
body: <p>I have a class like:</p>
  <pre><code>class Cls(object):
       foo = MyItem()
       bar = 'hello'
       def __init__(self, test):
            self.test = test
  
       def func(self):
           return 'call me'
  </code></pre>
  <p>I want to loop through class members only if they are callable items like <code>foo</code>. In fact MyItem() class implements a <code>__call__</code> function inside, but it also has attributes like name.</p>
  <p>This is MyItem class</p>
  <pre><code>class MyItem(object):
      widget = LabelValue()
      name = &quot;&quot;
      data = &quot;&quot;
      def __init__(self, name=&quot;&quot;, label=&quot;&quot;, info={}, widget=None):
          if widget is not None:
              self.widget = widget
          self.name = name
          self.label = label
          self.info = info
      def __call__(self, **kwargs):
          self.widget(item =self, **kwargs)
  </code></pre>
  <p>I added this function to my class:</p>
  <pre><code>    def __iter__(self):
          for attr in dir(self):
              if not attr.startswith(&quot;__&quot;) and callable(getattr(self, attr)):
                  yield getattr(self, attr)
  </code></pre>
  <p>And I tested it like:</p>
  <pre><code>r = {}
  for i in Cls():
      r[i] = i
  </code></pre>
  <p>It iterate through MyItem objects, but if I want to access name like</p>
  <pre><code>for i in Cls():
      r[i] = i.name
  </code></pre>
  <p>it throws:</p>
  <pre><code>    AttributeError: 'function' object has no attribute 'name'
  </code></pre>
  <p>Also if I could somehow have all such members as a list and add to class like <code>_myitems</code> would be good, but I don't know how to do that too.</p>