Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@load should provide better error message when symbol is passed without variable names #51

Closed
ngphuoc opened this issue Nov 16, 2017 · 5 comments

Comments

@ngphuoc
Copy link

ngphuoc commented Nov 16, 2017

julia>   using JLD2,FileIO

julia>   data = 1
1

julia>   fn = "data.jld2"
"data.jld2"

julia>   JLD2.@save fn data

julia>   JLD2.@load fn
ERROR: MethodError: no method matching jldopen(::Symbol)
Closest candidates are:
  jldopen(::AbstractString) at /home/phuoc/.julia/v0.6/JLD2/src/JLD2.jl:286
  jldopen(::AbstractString, ::Bool, ::Bool, ::Bool) at /home/phuoc/.julia/v0.6/JLD2/src/JLD2.jl:201
  jldopen(::AbstractString, ::Bool, ::Bool, ::Bool, ::T<:Union{Type{IOStream}, Type{JLD2.MmapIO}}; compress, mmaparrays) where T<:Union{Type{IOStream}, Type{JLD2.MmapIO}} at /home/phuoc/.julia/v0.6/JLD2/src/JLD2.jl:201
  ...
@simonster
Copy link
Member

If you don't give it variable names, the load macro needs to know the path to the filename at macro expansion time, since it needs to read the file to determine the variable names. But there could be a better error message for this.

@simonster simonster changed the title @load does not accept variable as filename @load should provide better error message when non-literal is passed without variable names Nov 18, 2017
@simonster simonster changed the title @load should provide better error message when non-literal is passed without variable names @load should provide better error message when symbol is passed without variable names Nov 18, 2017
@floswald
Copy link

yes I've been looking around for that ::Symbol as well before I realized that I need to provide a variable name.

@tk3369
Copy link

tk3369 commented Jun 10, 2018

I just came across this issue. Is there any way to use the @load macros with a variable then?

@luboshanus
Copy link

After a lot of time spent by looking for a use of the @load with variables inside the name of a file, there is a way. Sorry, if this comment is too obvious but the solution was not that obvious for me.

# saving
for i in 1:2
	xx = zeros(2,2)
	@save "temp$i.jld2" xx
end
# loading
for i in 1:2
    @eval @load $("temp$i.jld2")
end

@JonasIsensee
Copy link
Collaborator

The above is also not a great option since it evals into global scope..
This might not work inside functions.

Generally I'd recommend to either use the jldopen or the FileIO load syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants