Я пытаюсь понять, почему использование переменной i
внутри цикла вызывает проблему
Файл main2.jl :
struct MyStruct
a::Int32
b::Int32
c::String
end
df = DataFrame( A=Int[], B=Int[] )
push!(df, [1, 10])
push!(df, [2, 20])
push!(df, [3, 30])
insertcols!(df, 3, :C => MyStruct.(Int32(0), Int32(0), ""))
insertcols!(df, 3, :D => Vector{MyStruct})
println(df)
i = 1
for r in eachrow(df)
i = i + 1
end
Я получаю:
julia> include("main2.jl")
| A | B | D | C |
| Int64 | Int64 | DataType | MyStruct |
|-------|-------|-------------------|----------------------|
| 1 | 10 | Array{MyStruct,1} | MyStruct(0, 0, \"\") |
| 2 | 20 | Array{MyStruct,1} | MyStruct(0, 0, \"\") |
| 3 | 30 | Array{MyStruct,1} | MyStruct(0, 0, \"\") |
ERROR: LoadError: UndefVarError: i not defined
Stacktrace:
[1] top-level scope at /usr/home/.../main2.jl:19
[2] include at ./boot.jl:328 [inlined]
[3] include_relative(::Module, ::String) at ./loading.jl:1094
[4] include(::Module, ::String) at ./Base.jl:31
[5] include(::String) at ./client.jl:431
[6] top-level scope at REPL[3]:1
in expression starting at /usr/home/.../main2.jl:18
julia>