title: Python casting and strange type convertion
body: <p>I have a piece of code which is supposed to create and sort the list of file by their size. Here it is:</p>
  
  <pre><code>class DataScript(object):
  
  def __init__(self, index, name, size):
      self.index = index
      self.name = name
      self.size = size
  
  def __cmp__(self, other):
      if hasattr(other, 'getKey'):
          return self.getKey().__cmp__(other.getKey())
  
  def getKey(self):
      return self.size
  
  def __iter__(self):
      return self
  
  def __next__(self):
      self.index += 1
      try:
          return data[self.index - 1]
      except IndexError:
          self.idx = 0
          raise StopIteration  # Done iterating.
  
  
  resultList = []
  data = [d for d in os.listdir(dirpath) if '_DATA_TABLE' in d]
  i=0
  for file in data:
      fileinfo = os.stat(join(dirpath, file))
      file_obj = DataScript(i, file, float(fileinfo.st_size))
      if isinstance(file_obj, DataScript):
          resultList.extend(file_obj)
  
      i=i+1
  
  items = resultList
  for i in range(len(items)):
      for j in range(len(items) - 1 - i):
          item1 = items[j]
          item2 = items[j+1]
          if isinstance(item1, DataScript) and isinstance(item2, DataScript):
              if item1.__cmp__(item2)&gt;0:
                  items[j] = item2
                  items[j+1] = item1
  resultList = items
  </code></pre>
  
  <p>Everything works but not exactly as expected. The result list at the end is not sorted list of DataScript objects but strings. Why ?
  As an effect my sorting piece at the end doesn't work.</p>