On Apr 8, 9:34 am, Paul Rubin http://[EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] writes:
a) def flip(f): return lambda x,y: f(y,x)
Curious resemblance to:
itemgetter(1,0)
Not sure I understand that.
I think he read it as lambda (x, y): (y, x)
More interesting would be
Klaas [EMAIL PROTECTED] writes:
Still don't see much advantage over writing a lambda (except perhaps
speed).
Well, it's partly a matter of avoiding boilerplate, especially with
the lambdaphobia that many Python users seem to have.
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] (Alex Martelli) writes:
4. functools enhancements (Haskell-inspired):
Let f be a function with 2 inputs. Then:
a) def flip(f): return lambda x,y: f(y,x)
b) def lsect(x,f): return partial(f,x)
c) def rsect(f,x): return partial(flip(f), x)
[Paul Rubin]
1. File iterator for blocks of chars:
f = open('foo')
for block in f.iterchars(n=1024): ...
for block in iter(partial(f.read, 1024), ''): ...
iterates through 1024-character blocks from the file. The default iterator
a) def flip(f): return lambda x,y:
[EMAIL PROTECTED] writes:
for block in f.iterchars(n=1024): ...
for block in iter(partial(f.read, 1024), ''): ...
Hmm, nice. I keep forgetting about that feature of iter. It also came
up in a response to my queue example from another post.
a) def flip(f): return lambda x,y:
I just had to write some programs that crunched a lot of large files,
both text and binary. As I use iterators more I find myself wishing
for some maybe-obvious enhancements:
1. File iterator for blocks of chars:
f = open('foo')
for block in f.iterchars(n=1024): ...
iterates
Paul Rubin http://[EMAIL PROTECTED] writes:
# loop through all the files crunching all lines in each one
for line in (ichain(file_lines(x) for x in all_filenames)):
crunch(x)
supposed to say crunch(line) of course.
--
http://mail.python.org/mailman/listinfo/python-list
Paul Rubin http://[EMAIL PROTECTED] wrote:
I just had to write some programs that crunched a lot of large files,
both text and binary. As I use iterators more I find myself wishing
for some maybe-obvious enhancements:
1. File iterator for blocks of chars:
f = open('foo')
[EMAIL PROTECTED] (Alex Martelli) writes:
for line in file_lines(filename):
crunch(line)
I'm +/-0 on this one vs the idioms:
with open(filename) as f:
for line in f: crunch(line)
Making two lines into one is a weak use case for a stdlib function.
Well, the