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 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/

相关文章:

python - Julia (v1.3.1) 中是否存在 `logspace` 的任何替代方案?

julia - 极其稀疏整数二次规划

dataframe - Julia 中的动态函数名称定义.. 可能吗?

Julia:具有唯一整数的 Vector 的 `n` 条目的所有可能总和(有重复)

centos - Julia + Centos - Arpack 无法构建

python - 在 Julia 中加速 kNN 函数

web-scraping - Julia :网站抓取?

julia - 如何将 bang 字符添加到仿函数?

struct - 如何在 Julia 中为可变结构设置默认参数?

windows - Julia,Windows 10 上的 ArchGDAL 安装错误