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

pyimport syntax: from <module> import <symbol> #66

Closed
cncastillo opened this issue Feb 22, 2014 · 7 comments
Closed

pyimport syntax: from <module> import <symbol> #66

cncastillo opened this issue Feb 22, 2014 · 7 comments

Comments

@cncastillo
Copy link

Maybe in @pyimport macros you could add some other sintaxis, for example if the user dont need to load all the package and only one function or more of it:

@pyimport from numpy import zeros, array, fromtxt
@pyimport from mayavi import mlab
@pyimport from scipy.ndimage import gaussian_filter as filter
@stevengj
Copy link
Member

I would prefer to use the Julian syntax here (when in Rome...): @pyimport numpy: zeros, array, fromtxt etcetera.

@hammer
Copy link

hammer commented Jul 9, 2014

+1 been laboring with multi-line import statements due to lack of this feature.

@stevengj
Copy link
Member

stevengj commented Jul 9, 2014

I'm a little worried about namespace conflicts. If I implement @pyimport numpy: zeros for example, by setting const zeros = pyimport("numpy")[:zeros], then I will overwrite the built-in Julia zeros function. It seems safer just to require you to call numpy.zeros(...).

@hammer, can you give a concrete example where this would be important to you?

@marius311
Copy link
Contributor

Obviously this is 2 years old, but maybe something has changed since then that warrants adding this? I think it'd be a great feature. I don't have concrete examples to add, just to say that obviously it would allow writing more concise easier-to-read code in many cases.

As for overwriting, once I've written @pyimport numpy: zeros doesn't that mean I want the overwriting to happen? Its not like it'd be unexpected in some way.

@stevengj
Copy link
Member

Honestly, I'm thinking of getting rid of @pyimport completely, and telling people to just do numpy = pyimport("numpy"). The reason is that it is confusing that you can use . to get the members of a @pyimport module, but for everything else you need foo[:bar].

You can still just do z = pyimport("numpy")[:zeros], so a Pythonic syntax doesn't actually give you any new functionality.

@cstjean
Copy link
Collaborator

cstjean commented Sep 16, 2016

I would prefer to use the Julian syntax here (when in Rome...): @pyimport numpy: zeros, array, fromtxt etcetera.

I implemented it in ScikitLearn:

using ScikitLearn.Skcore: @pyimport2
@pyimport2 scipy.ndimage: (gaussian_filter, fourier_uniform)

but I struggled to get the hygiene right. I can make a PR for it if there is interest.

Honestly, I'm thinking of getting rid of @pyimport completely, and telling people to just do numpy = pyimport("numpy").

-1 for me, that would get tiring.

@marius311
Copy link
Contributor

marius311 commented Sep 16, 2016

Thanks guys, yea @pyimport2 is exactly what I'm looking for, helpful to know that's there.

Re: removing @pyimport completely, its true its slightly inconsistent that you get to use the dot notation for the first level, but honestly as a user that was pretty easy to figure out from skimming your docs and trying a few simple examples. For me it'd seem to be sacrificing too much convenience in the name of consistency. My own +1, as you could probably guess, would instead be incorporating the @pyimport2 functionality into PyCall.

cstjean added a commit to cstjean/PyCall.jl that referenced this issue Nov 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants