为什么这个 for 循环不能运行两次?(朱莉娅)



我先打开了一些文本文件。

r = open("sample_text.txt","r")

我用这个代码按行拆分。

for line in eachline(r)
println(line)
println(typeof(line))
end

并获取结果

A novel is a relatively long work of narrative fiction, normally written in prose form, and which is typically published as a book. The present English word for a long work of prose fiction derives from the Italian: novella for "new", "news", or "short story of something new", itself from the Latin: novella, a singular noun use of the neuter plural of novellus, diminutive of novus, meaning "new".
String
String
Some novelists, including Nathaniel Hawthorne, Herman Melville, Ann Radcliffe, John Cowper Powys, preferred the term "romance" to describe their novels.
String

但如果我再次运行forr循环,我没有得到任何结果。为什么我会遇到这种问题?

您已经从文件流中读取了所有数据。

如果你想再次阅读,你需要重置光标的位置:

seekstart(r)

最新更新