I’m trying to use ‘izip’ to read lines simultaneously from two files, however got errors like below:
>>> f1=open('/home/xug/scratch/test/test_1.fastq','r')
>>> f2=open('/home/xug/scratch/test/test_2.fastq','r')
>>> from itertools import izip
>>> for i,line1,line2 in izip(f1,f2):
... if i%4==3:
... print line1,line2
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: need more than 2 values to unpack
I don’t know why….what is “need more than 2 values”?
thx
izip()simply zips the two iterables to pairs. It doesn’t introduce an additional counter, as you seem to expect. Try usingenumerate()to also get that counter.
The error message results from the attempt to assign the first item of your iterable to
i, line1, line2. Since the first item is a pair of strings, says1ands2, this assignment would be essentially equivalent towhich would clearly needs more than two values to unpack. (To be precise, it would need three.)