PyCall.jl
PyCall.jl copied to clipboard
Add the `from module import a as b` syntax to PyCall
I have implemented a macro to replicate the from module import a as b, c as d
syntax as @pyfrom module import a as b, c as d
https://github.com/AutoActuary/PyFrom.jl
Would it be possible to get something like this into PyCall?
no one opposed this, you should file a PR!
I agree, or at least state in the readme that it's not supported and what the canonical way of importing submodules is (I couldn't find it).
Alternatively a more Julian way, like @pyimport NiceStuff: nice, DOG
could also be nice.
PythonCall has something like this with @py
.
I had a look at this issue again today and saw that @pyimport
is marked as deprecated in the source code:
https://github.com/JuliaPy/PyCall.jl/blob/b27bd5a9ecabec4a30ba6062c3754768746e3adb/src/PyCall.jl#L413
Is this correct and intended? In this case, should @pyimport
even be considered?
Is does remove quite a bit of boilerplate code in the case of a nested imports or renaming, e.g. @pyfrom scipy.ndimage import gaussian_filter
or @pyfrom scipy.ndimage import gaussian_filter as blur
This works and is not much more code than the proposed syntax:
gaussian_filter = pyimport("scipy.ndimage").gaussian_filter
blur = pyimport("scipy.ndimage").gaussian_filter
In general, I'm not super excited about imitating Python syntax in Julia.