在 Julia 中逐行阅读 [英] Reading line by line in Julia
本文介绍了在 Julia 中逐行阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从每行包含一些整数的文件中读取数据
I am trying to read from a file where each line contains some integer
但是当我这样给予时
f=open("data.txt")
a=readline(f)
arr=int64[]
push!(arr,int(a))
我得到了
ERROR: no method getindex(Function)
in include_from_node1 at loading.jl:120
推荐答案
错误来自 int64[]
,因为 int64
是一个函数,您正在尝试索引它与 []
.要创建 Int64
数组(注意大小写),您应该使用,例如,arr = Int64[]
.
The error comes from int64[]
, since int64
is a function and you are trying to index it with []
. To create an array of Int64
(note the case), you should use, e.g., arr = Int64[]
.
您的代码中的另一个问题是 int(a)
- 由于您有一个 Int64
数组,因此您还应该在解析时指定相同的类型,例如 push!(arr,parseint(Int64,a))
Another problem in your code is the int(a)
- since you have an array of Int64
, you should also specify the same type when parsing, e.g., push!(arr,parseint(Int64,a))
这篇关于在 Julia 中逐行阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文