編集:OK、私はバグとそれを再現するための正確で完全なコードを分離することができました。しかし、それは仕様によるものか、Pythonのバグのいずれかであるように見えます。
もちろん、 2つの兄弟パッケージを作成します。 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
。これは、1つのファイルが例外と同じディレクトリにある場合にのみ発生するため、インポート方法が異なります。
これは仕様によるものですか、それともPythonのバグですか?
私はpython2.6を使用しており、eclipse+pydevで実行しています。