Julia 为什么这个for循环可以';你不能跑两次吗?(朱莉娅)
我先打开了一些文本文件Julia 为什么这个for循环可以';你不能跑两次吗?(朱莉娅),julia,Julia,我先打开了一些文本文件 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 whi
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)
eachline
迭代文件,循环结束时将指针留在文件末尾。所以在你第二次尝试阅读的时候,没有什么可以读的。。。使用读取行
将行保存到数组中,再次打开文件,或使用查找
重置文件指针