title: error in a python class with an not iterable object
body: <p>i have a the following error message</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 2721, in run_code
      exec code_obj in self.user_global_ns, self.user_ns
    File "&lt;ipython-input-257-84ae6ec7b6f6&gt;", line 1, in &lt;module&gt;
      accuracy.ra_os
    File "&lt;ipython-input-255-a91d95432efe&gt;", line 32, in ra_os
      return np.average([(ref.intersection(s).area/s.area) for s in seg])
  TypeError: 'Polygon' object is not iterable
  </code></pre>
  
  <p>where Polygon is the <code>Polygon class</code> of <a href="http://toblerity.github.com/shapely/manual.html" rel="nofollow">shapely</a>.</p>
  
  <p>i have my own class Accuracy: stat values between reference (one) and segmented (one or more) polygons</p>
  
  <pre><code>ref = &lt;shapely.geometry.polygon.Polygon at 0x4997b38&gt;
  seg = [&lt;shapely.geometry.polygon.Polygon at 0x4b972e8&gt;, &lt;shapely.geometry.polygon.Polygon at 0x49c7390&gt;]
  
  
  
  import math
  import numpy as np
  from shapely.geometry import Polygon
  nan = np.nan
  
  
  
  class Accuracy(object):
      def __init__(self, ref, seg=None):
          self.ref = ref
          self.seg = seg
  
      @property
      def area(self):
          return self.ref.area
  
      @property
      def perimeter(self):
          return self.ref.length
  
      @property
      def centroidX(self):
          return self.ref.centroid.x
  
      @property
      def centroidY(self):
          return self.ref.centroid.y
  
      @property
      def segments(self):
          if self.seg:
              return len(self.seg)
          else:
              return 0
  
      @property
      def ra_or(self):
          if self.seg:
              return np.average([(ref.intersection(s).area/ref.area) for s in seg])
          else:
              return nan
  
      @property
      def ra_os(self):
          if self.seg:
              return np.average([(ref.intersection(s).area/s.area) for s in seg])
          else:
              return nan
  </code></pre>
  
  <p>accuracy = Accuracy(ref, seg_overlap)
  accuracy.ra_os</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 2721, in run_code
      exec code_obj in self.user_global_ns, self.user_ns
    File "&lt;ipython-input-45-84ae6ec7b6f6&gt;", line 1, in &lt;module&gt;
      accuracy.ra_os
    File "&lt;ipython-input-7-1e04291926b0&gt;", line 35, in ra_os
      return np.average([(ref.intersection(s).area/s.area) for s in seg])
  TypeError: 'Polygon' object is not iterable
  </code></pre>
  
  <p>if i run the function outside the class i have not this error</p>
  
  <pre><code>np.average([(ref.intersection(s).area/ref.area) for s in seg_overlap])
  Out[47]: 0.48709794373000681
  </code></pre>