Congruence of 'map' and 'for' broken in 2.1??
Alex Martelli
aleaxit at yahoo.com
Sat Apr 28 04:12:53 EDT 2001
<nanotech at europa.com> wrote in message
news:mailman.988402866.799.python-list at python.org...
[snip]
> >>> print reduce(lambda x, y: x+y, map(int,fh.xreadlines()))
> Traceback (most recent call last):
> File "<pyshell#91>", line 1, in ?
> print reduce(lambda x, y: x+y, map(int,fh.xreadlines()))
> TypeError: argument 2 to map() must be a sequence object
>
> Ack!! Why will map not fudge? What am I missing?? Is it pilot error??
I think map() needs to know the *length* of its sequence arguments,
and the object returned by .xreadlines() doesn't/can't supply it -- it's
more of an "undetermined-length sequence" (sensibly-- how would
length be determined without reading everything?).
Since we don't formally have interfaces/protocols in Python, but
rely on informal docs, such ambiguities recur -- it's never really
clear when the docs say "a sequence" whether they mean a length
is needed or not, just like "a function" may be any callable in
many cases but not all, etc. PEP 245/246 might help...
Alex
More information about the Python-list
mailing list