This works in a code file where fname is a string that is a path to a file:
println(read(fname, String))
But, it doesn’t work in the REPL. Weird. Shouldn’t it be the same for both? I copy it from the code file and paste in the path and get:
println(read("/Users/me/Dropbox/Online Coursework/ML Independent explorations/nn by hand/nnstats-2018-07-20T10-04-45-782.txt",String))
ERROR: MethodError: Cannot `convert` an object of type Type{String} to an object of type Array{UInt8,1}
This may have arisen from a call to the constructor Array{UInt8,1}(...),
since type constructors fall back to convert methods.
From the convert error it looks like Julia is treating the string (the value of fname) as the thing to read and convert to String. But, the method should interpret the string as a filename.
There are 37 read methods and this is the only one that could match:
read(filename::AbstractString, args...) in Base at io.jl:160
Not sure if the args can be functions or a constructor function.
As an alternative, this works in the REPL: println(String(read(fname)))
I am sure it used to work. And I saw this shortcut somewhere as I wouldn’t have thought it could work. Having seen it I used it for a tiny little status file.
Again, it works perfectly in the script (actually, a function) so I am confused.