I am trying do the following:
import functools
class TestClass():
def method(self, n):
for i in xrange(n):
yield i
# This works
for x in TestClass().method(10):
print x
# This gets a TypeError: functools.partial object not iterable
for x in functools.partial(TestClass().method, 10):
print x
What wrong there?
functools.partial
creates an object that behaves like a new function that mimics the old function with some arguments 'frozen'. So you have to actually call this new function to get the same output:
for x in functools.partial(TestClass().method, 10)():
print x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With