On Feb 24, 5:11 am, gert <[EMAIL PROTECTED]> wrote:
> what is the difference between iter(lambda:f.read(8192), ') and
> iter(f.read(8192),'') ?
One does not work, and one is syntactically incorrect:
>>> iter(f.read(8192),'')
Traceback (most recent call last):
File "", line 1, in
iter(f.read(8192),'')
TypeError: iter(v, w): v must be callable
>>> iter(lambda:f.read(8192), ')
SyntaxError: EOL while scanning single-quoted string
To clarify:
f.read(8192) returns the next 8192 bytes of the file in a string, or
whatever is leftover, or an empty string when the file is exhausted.
lambda: f.read(8192) is a function that will return the next 8192
bytes of the file every time it is called.
So iter(f.read(8192),'') is evaluated as iter(some_string, ''). When
iter receives two arguments, it expects the first to be a function,
not a string.
iter(lambda:f.read(8192), '') (what you probably meant) is what it
looks like: iter(some_func, '').
--
http://mail.python.org/mailman/listinfo/python-list