Reading line by line in Julia

I am trying to read from a file where each line contains some integer

But when I gave it

f=open("data.txt")
a=readline(f)
arr=int64[]
push!(arr,int(a))

I get

ERROR: no method getindex(Function)
 in include_from_node1 at loading.jl:120
+3
source share
1 answer

The error occurs from int64[], as it int64is a function, and you are trying to index it with []. To create an array int64(note the case), you should use, for example arr = Int64[].

Another problem in your code is int(a)- since you have an array int64, you must also specify the same type when parsing, e.g.push!(arr,parseint(Int64,a))

+6
source

All Articles