|
|
|
|
|
by throwaway_pdp09
2207 days ago
|
|
very quick reply, and I've done this in other langs that allow procedures-done-as-lambdas, create your own control flow mechanisms with 'reasonable' syntax, something like with_file("c:/blah/data.csv", lambda fl:
# do stuff with file variable fl
# other statements
# ...
)
The file is opened, the block of code of the lambda does its thing, the file is closed at the end, exception-safe.Python can do this another way (with 'with' objects or something, and it's quite clean and neat, but that's quite recent IIRC), this simpler IMO. Have used this, it's called the loan pattern, in scala, vb.net and C#, and prob others. The arbitrary restriction on lambdas blocks composability, which disallows useful tricks like this. |
|