where is the python "import" implemented
in this situation, I can not find the source code how python implement it. I test a wrong format pyc, and got a error "ImportError: bad magic number",and I search "bad magic number" in the source code, I find it is in importlib/_bootstrap.py(line 815),but when I modify this error info(eg: test bad magic) and run again, nothing is changed. It seems that the file is not the correct position.
This is the right position. When you change _bootstrap.py, you need to run "make" again, to freeze the modified _bootstrap.py. Regards, Martin
Hello, Le Tue, 11 Dec 2012 14:08:27 +0800, "Isml" <76069016@qq.com> a écrit :
Hi, everyone, I am testing modifying the pyc file when it is imported. As I know, there is three situation: 1、runing in the python.exe eg: python.exe test.pyc in this situation, I find the source on line 1983 in file pythonrun.c 2、import the pyc from a zip file I find the source on line 1132 in zipimport.c 3、do a normal import eg: two file : main.py and testmodule.py and in main.py: import testmodule
in this situation, I can not find the source code how python implement it. I test a wrong format pyc, and got a error "ImportError: bad magic number",and I search "bad magic number" in the source code, I find it is in importlib/_bootstrap.py(line 815),but when I modify this error info(eg: test bad magic) and run again, nothing is changed. It seems that the file is not the correct position.
importlib/_bootstrap.py is indeed the place, but you need to run "make" once you have modified that file. _bootstrap.py is frozen into the executable at compile time, because otherwise the bootstrap issues are intractable. Regards Antoine.
participants (3)
-
Antoine Pitrou
-
Isml
-
martin@v.loewis.de