在Julia中有没有等同于python的with open()习惯用法的东西?
>>> with open(path, "r") as file:
... file.readlines()
['beep\n', 'boop\n']发布于 2021-03-06 00:00:22
我不知道最常用的方法是什么,但你有几个选择:
julia> readlines("tmp.log")
2-element Array{String,1}:
"beep"
"boop"julia> read(file, String)
"beep\nboop\n"julia> open("tmp.log", "r") do file
while !eof(file)
@show readline(file)
end
end
readline(file) = "beep"
readline(file) = "boop"julia> for line in eachline("tmp.log")
@show line
end
line = "beep"
line = "boop"有关更多信息,请参阅docs。
https://stackoverflow.com/questions/66495720
复制相似问题