I’m trying to add the current directory to sys.path
. The step works if I set index using a string, but fails for the recommended dot overload, or if I use a symbol to access the path.
julia> using PyCall
julia> s=pyimport("sys")
PyObject <module 'sys' (built-in)>
julia> s.path
4-element Array{String,1}:
"/project/jb6888/anaconda3/lib/python37.zip"
"/project/jb6888/anaconda3/lib/python3.7"
"/project/jb6888/anaconda3/lib/python3.7/lib-dynload"
"/project/jb6888/anaconda3/lib/python3.7/site-packages"
julia> pushfirst!(PyVector(s.path),pwd())
PyObject ['/home/jb6888', '/project/jb6888/anaconda3/lib/python37.zip', '/project/jb6888/anaconda3/lib/python3.7', '/project/jb6888/anaconda3/lib/python3.7/lib-dynload', '/project/jb6888/anaconda3/lib/python3.7/site-packages']
julia> s.path
4-element Array{String,1}:
"/project/jb6888/anaconda3/lib/python37.zip"
"/project/jb6888/anaconda3/lib/python3.7"
"/project/jb6888/anaconda3/lib/python3.7/lib-dynload"
"/project/jb6888/anaconda3/lib/python3.7/site-packages"
The sys.path
is unchanged this way. Using a symbol doesn’t work as well
julia> pushfirst!(PyVector(s[:path]),pwd())
┌ Warning: `getindex(o::PyObject, s::Symbol)` is deprecated in favor of dot overloading (`getproperty`) so elements should now be accessed as e.g. `o.s` instead of `o[:s]`.
│ caller = top-level scope at none:0
└ @ Core none:0
PyObject ['/home/jb6888', '/project/jb6888/anaconda3/lib/python37.zip', '/project/jb6888/anaconda3/lib/python3.7', '/project/jb6888/anaconda3/lib/python3.7/lib-dynload', '/project/jb6888/anaconda3/lib/python3.7/site-packages']
julia> s.path
4-element Array{String,1}:
"/project/jb6888/anaconda3/lib/python37.zip"
"/project/jb6888/anaconda3/lib/python3.7"
"/project/jb6888/anaconda3/lib/python3.7/lib-dynload"
"/project/jb6888/anaconda3/lib/python3.7/site-packages"
but using a string works even though the method is deprecated
julia> pushfirst!(PyVector(s["path"]),pwd())
┌ Warning: `getindex(o::PyObject, s::AbstractString)` is deprecated in favor of dot overloading (`getproperty`) so elements should now be accessed as e.g. `o."s"` instead of `o["s"]`.
│ caller = top-level scope at none:0
└ @ Core none:0
PyObject ['/home/jb6888', '/project/jb6888/anaconda3/lib/python37.zip', '/project/jb6888/anaconda3/lib/python3.7', '/project/jb6888/anaconda3/lib/python3.7/lib-dynload', '/project/jb6888/anaconda3/lib/python3.7/site-packages']
julia> s.path
5-element Array{String,1}:
"/home/jb6888"
"/project/jb6888/anaconda3/lib/python37.zip"
"/project/jb6888/anaconda3/lib/python3.7"
"/project/jb6888/anaconda3/lib/python3.7/lib-dynload"
"/project/jb6888/anaconda3/lib/python3.7/site-packages"
I’m using PyCall v1.91.2, which seems to be the recent version