I have 3 files. xxx which imports xxx2 and xxx2 imports xxx3 which one raises OppsError exception.
xxx3.py:
class OppsError(Exception):pass
def go():
    raise OppsError()
xxx2.py:
import xxx3
xxx3.go()
xxx.py:
try:
    import xxx2
except xxx3.OppsError:
    print 'ops'
When i run xxx.py i get error NameError: name 'xxx3' is not defined. Is importing 开发者_JAVA技巧xxx3 inside xxx only way to catch OppsError?
As far as I know, it is (unless you are willing to replace OppsError with a built-in exception that is already known to xxx or to catch a more general exception instead of OppsError from which OppsError is derived).
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论