Python Closures Example Code
- by user336527
I am learning Python using "Dive Into Python 3" book. I like it, but I don't understand the example used to introduce Closures in Section 6.5.
I mean, I see how it works, and I think it's really cool. But I don't see any real benefit: it seems to me the same result could be achieved by simply reading in the rules file line by line in a loop, and doing search / replace for each line read.
Could someone help me to:
either understand why using closures in this example improves the code (e.g., easier to maintain, extend, reuse, or debug?)
or suggest a source of some other real-life code examples where closures really shine?
Thank you!