-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
pylab overwrites user variable(s) #1566
Comments
Not a bug (technically). Your imports should always come first. This is also another example of the dangers of "from foobar import *". |
Yup: >>> f = 10
>>> import pylab as p
>>> f
10
>>> p.f
<built-in method f of mtrand.RandomState object at 0x1083341b0> |
I agree about the dangers of |
I noticed this in IPython. I wanted to plot some data and after entering %pylab mode, it overwrite my file handle (hdf5) which was assigned to
|
The problem comes from numpy:
Which is imported in I'm not sure we can reliably do much here other than |
Note, the offending numpy line: https://github.com/numpy/numpy/blob/master/numpy/random/mtrand/mtrand.pyx#L4481 |
On Thu, Dec 6, 2012 at 4:21 AM, Phil Elson notifications@github.com wrote:
Nope, it won't clobber it. See following example: foo.py: bar.py: $ python bar.py But in the end, perhaps we need to consider just explicitly importing in |
tbh, to beat an already well beaten drum, the whole
Agreed. I would sooner do it the other way round - i.e. |
Yeah -- it's not an easy problem. Though I agree for scripts/code it's almost never a good idea to It's never really been defined what's supposed to be in pylab -- it includes things both from matplotlib and numpy (deliberately), but not by explicitly listing things -- so it's kind of dynamic based on the contents of numpy and pyplot. So it's kind of a slippery slope to start removing things when end users may be relying on them being there. I know I was the first to suggest it, but maybe it's best to just not tackle this at all. We already encourage users to do I guess I'm starting to see that instating a policy of trying to prune pylab may lead to a very unbounded project. |
To be more blunt, pruning would be a big mistake. Where would one stop? Why should some names start to disappear, while other likely variable names would not? In that list from RandomState, "f" is not the only name commonly used as a variable--consider "beta", "gamma", "seed", "choice"--all perfectly reasonable variable names that a user might want to use. And "f" is as much a valid standard name for its function as the other names in that group are for theirs. This is a clear "won't fix" case. |
Also note that the |
The text was updated successfully, but these errors were encountered: