try: except: not working

后端 未结 3 2149
青春惊慌失措
青春惊慌失措 2021-02-20 13:48

So I\'m running into a problem where the try: except: mechanism doesn\'t seem to be working correctly in python.

Here are the contents of my two files.

pyte

3条回答
  •  鱼传尺愫
    2021-02-20 14:30

    The main python program is always imported as the module __main__.

    When you import pytest2, it doesn't reuse the existing module because the originally imported module has the name __main__ not pytest2. The result is that pytest1 is run multiple times generating multiple exception classes. __main__.MyError and pytest1.MyError You end up throwing one and trying to catch the other.

    So, don't try to import your main module from other modules.

提交回复
热议问题