我先打开了一些文本文件。
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)
关于julia - 为什么这个 for 循环不能运行两次? ( Julia ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65530610/