라이브러리를 가져 와서 예외를 catch하고 싶습니다.파이썬 라이브러리 가져 오기 및 사용할 수없는 경우 정상적으로 처리
블록 잡기 시도가 1 개 밖에없는 경우 첫 번째 예외가 발생합니다. 모든 libs를 반복하고 각 개별 lib에 대해 별도의 예외가있는 패턴이 있습니까?
#!/usr/bin/env python
try: import sys
except: print sys.exc_info()
try: import numpy as np
except: print sys.exc_info()
try: import scipy as sp
except: print sys.exc_info()
try: import os as os
except: print sys.exc_info()
try: from operator import itemgetter
except: print sys.exc_info()
try: import socket
except: print sys.exc_info()
try: import logging
except: print sys.exc_info()
try: from time import gmtime, strftime
except: print sys.exc_info()
귀하의 예외 처리기가 완전히 경우 실패 할
: 예를 들어
'sys '를 가져 오지 못합니다. –
표준 라이브러리는 여기에서 제외합니다. 왜 그것들을 가져 오는 것이 실패 *할까요? –
이러한 가져 오기 중 하나라도 실패하면 코드가 작동해야하는 이유는 무엇입니까? 당신의 코드가'sp' 나'np'를 처리 할만큼 강력합니까? –