Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 21st, 2012  |  syntax: None  |  size: 0.34 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. >>> class X(object):
  2. ...   def __getattribute__(self, name):
  3. ...     if name == "__iter__":
  4. ...       import new
  5. ...       return new.instancemethod(lambda self: iter([1,2,3,4]), self, X)
  6. ...  
  7. ...   def __iter__(self):
  8. ...     return iter([9,10,11,12])
  9. ...
  10. >>> x = X()
  11. >>> list(x)
  12. [9, 10, 11, 12]
  13. >>> list(x.__iter__())
  14. [1, 2, 3, 4]