user567879
user567879

Reputation: 5339

Reading line by line in Julia

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

Upvotes: 3

Views: 4422

Answers (1)

Arkku
Arkku

Reputation: 42109

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

Upvotes: 6

Related Questions