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
Silent importing of submodules differs from standard Python3.2 interpreter's behavior #2956
Comments
I think it's just that IPython had already imported To check: In [1]: import sys; print('urllib.request' in sys.modules)
True and to further check your suspicions for modules in general with a dummy package: mkdir mymod
touch mymod/__init__.py
echo "foo=5" > mymod/submod.py
ipython In [1]: import mymod
In [2]: mymod.<TAB>
<no results>
In [3]: import mymod.submod
In [4]: mymod.<TAB>
In [4]: mymod.submod So I don't think anything untoward is going on. |
Thanks, minrk, for your quick reply. The only untoward thing is that after the user tests code on Ipython, the same code must be tested on the regular interpreter or command line, lest necessary modules not have been imported correctly. I wonder if there is a way to make this extra step unnecessary. |
I don't think there is anything to do, other than minimize the things IPython imports itself. The fact that one package's imports can affect how modules look to other code in the same process is just an artefact of how Python works. |
In this specific case, I think it should be fixed by #2868, which defers importing urllib until a method is called that needs it. |
All true, but the fact is that |
Just checked, this is fixed in master:
Do you see the issue with any other packages? |
Haven't noticed it elsewhere, but thank you! |
I agree there isn't much else we can do here. Python doesn't really allow modules to be imported multiple times, so this is (as @minrk pointed out) an artifact of the way IPython and your script share the same Python interpreter. Shall we close this issue? |
I have a question about Ipython3: importing modules that contain submodules. If I
import urllib as U
, I can then callU.request.urlopen()
and Ipython3 correctly loads the method in question.But if I use the same commands in the regular python3.2 interpreter, I get an error: "AttributeError: 'module' object has no attribute 'request' ".
It seems Ipython3 is loading submodules, unbidden, while python3.2 does not; that means that code may work on Ipython3 but not at the command line. Is this intentional? Is it documented? I do not see it in the docs, however.
(Environment: Python v. 3.2.3/Ipython 0.13.1 on Ubuntu 12.04 and OS 10.8)
The text was updated successfully, but these errors were encountered: