【发布时间】:2016-01-03 13:00:52
【问题描述】:
由于某种奇怪的原因,如果发生异常,我的 Python 解释器会执行文件 ./xml.py。我完全不知道为什么会发生这种情况 - 我绝对不希望这种情况发生。
我已经建立了一个新目录,其中包含一个名为 xml.py 的文件,其中仅包含“print("Hello xml.py")”行。启动 python3 后,我在解释器提示符处输入“a”。这应该向我显示一个简单的 NameError,因为 a 当然没有定义,而是打印“Hello xml.py”(即执行 ./xml.py)和一堆其他错误,然后才将 NameError 转储到屏幕上:
$ python3
Python 3.4.3 (default, Mar 26 2015, 22:03:40)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a
Hello xml.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
Error in sys.excepthook:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 15, in <module>
import xml.dom, xml.dom.minidom
ImportError: No module named 'xml.dom'; 'xml' is not a package
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
删除xml.py后一切恢复正常:
$ rm xml.py
$ python3
Python 3.4.3 (default, Mar 26 2015, 22:03:40)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>>
简单而简短的问题:这里到底发生了什么?
【问题讨论】:
标签: python python-3.x