编辑:好的,我设法隔离了错误和准确、完整的代码来重现它。但它看起来要么是设计的东西,要么是 python 中的错误。
创建两个兄弟包:admin
& General
,当然每个都有自己__init__.py
的。在包admin
中放入带有以下代码的文件“test.py”:
from General.test02 import run
import RunStoppedException
try:
run()
except RunStoppedException.RunStoppedException,e:
print 'right'
except Exception,e:
print 'this is what i got: %s'%type(e)
并admin
使用以下代码放入文件“RunStoppedException.py”:
class RunStoppedException(Exception):
def __init__(self):
Exception.__init__(self)
在包General
中放入包含代码的文件 test02.py:
import admin.RunStoppedException
def run():
raise admin.RunStoppedException.RunStoppedException()
打印输出:
this is what i got: <class 'admin.RunStoppedException.RunStoppedException'>
应该是什么时候right
。这只发生在一个文件与异常位于同一目录中时,因此它们以不同方式导入它。
这是设计使然,还是python的错误?
我用的是python2.6,在eclipse+pydev下运行