Reputation: 1
I have these two functions:
def getItems(r, c):
**do something**
**find and yield four values a, b, c, d**
yield (a,b,c,d)
def mainfunction(data):
reader = csv.reader(records)
for row in reader:
a,b,c,d = getItems(row, c)
yield (a,b,c,d)
However, when I run the file, I keep getting an error :
a, b, c, d = getItems(r, c)
ValueError: not enough values to unpack (expected 5, got 1)
I'm not sure how to proceed with this!
Upvotes: 0
Views: 269
Reputation: 42282
yield
converts the function to a generator, each yield
being one item of the iterator. The tuple is an other item. So your getItem
returns an iterable (~sequence) of tuples, even if it only yields one tuple, it's still an iterator of tuples.
Just replace the yield
by return
. Or if there's an actual reason for it to be there, you need to iterate the result of getItem
.
You could also yield the individual values such that getItem()
is an iterable of 4 elements but that doesn't seem very useful.
Upvotes: 2