本文介绍了在Julia逐行阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从文件中读取每行包含一些整数
但是,当我给这样的
错误来自 code>是一个函数,你试图用
您的代码中的另一个问题是 int(a) - 因为您有一个 Int64 ,你也应该在解析时指定相同的类型,例如, push!(arr,parseint(Int64,a)) p>
I am trying to read from a file where each line contains some integer
But when I gave like this
f=open("data.txt") a=readline(f) arr=int64[] push!(arr,int(a))I am getting
ERROR: no method getindex(Function) in include_from_node1 at loading.jl:120解决方案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[].
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逐行阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!