function open(f::Function, args...)
io = open(args...)
try
f(io)
finally
close(io)
end
end
Is there any reason this functionality coulden't be implemented here? Or perhaps theres design reasons against it? If not, I'd be interested in making a pull request (so long as this is as easy as I think it looks).
I never tried it, as I didn't see anything in the docs referring to it or descriptions of the open methods which accepted a function as a first argument.
For Julia's
Base.open
, you can call it from ado
block which automatically closes the file at the end and makes your code a little neater.This behaves the same as python's recommended way of reading files.
The source code for this is super simple.
Is there any reason this functionality coulden't be implemented here? Or perhaps theres design reasons against it? If not, I'd be interested in making a pull request (so long as this is as easy as I think it looks).