Is there an equivalent of "from <modul> import *" in PyCall?



Hello everyone,

I have started using Julia and PyCall. I think that the @pyimport feature is very nice but sometimes I find it more useful if I can do something like “from import *” like in Python. Is there any way I can do it?

Thank you.


There is no such functionality. But you can write a simple macro which will turn something like @from numpy import abs into @pyimport numpy as numpy; abs = numpy.abs.

Please note that doing from ... import * is a really bad thing and you never should do that, let alone in case of mixing Python with other languages.
Every single top level definition and import which is present in that Python module will be loaded in the current (global) namespace and can potentially cause horrible side effects.


Check out ImportMacros.jl for inspiration on how to implement similar macros that work with PyCall.jl:

I implemented @from if you have any doubts, feel free to ping me.