Skip to content

Instantly share code, notes, and snippets.

@terrycojones
Last active August 29, 2015 14:05
Show Gist options
  • Save terrycojones/9b3ca3e82e4cf868fa0c to your computer and use it in GitHub Desktop.
Save terrycojones/9b3ca3e82e4cf868fa0c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
class A(object):
def __iter__(self):
yield 'i'
yield 'am'
yield 'A'
def fiddleIter(self):
def newIter(_):
return iter(['i', 'am', 'new'])
self.__iter__ = newIter
class B(A):
def __iter__(self):
yield 'i'
yield 'am'
yield 'B'
b = B()
b.fiddleIter()
print b.__iter__
print list(b)
@terrycojones
Copy link
Author

In Python 2.7.2 this prints

<function newIter at 0x108663140>
['i', 'am', 'B']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment