[Python-Dev] anonymous blocks
Greg Ewing
greg.ewing at canterbury.ac.nz
Fri Apr 22 08:19:45 CEST 2005
Ka-Ping Yee wrote:
> Can you explain what you meant by currying here? I know what
> the word "curry" means, but i am having a hard time seeing how
> it applies to your example.
It's currying in the sense that instead of one function
which takes all the args at once, you have a function
that takes some of them (all except the thunk) and
returns another one that takes the rest (the thunk).
> Could you make up an example that uses more arguments?
def with_file(filename, mode):
def func(block):
f = open(filename, mode)
try:
block(f)
finally:
f.close()
return func
Usage example:
with_file("foo.txt", "w") as f:
f.write("My hovercraft is full of parrots.")
Does that help?
--
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg.ewing at canterbury.ac.nz +--------------------------------------+
More information about the Python-Dev
mailing list