python - How do I distinguish "module not found" from "module threw exception" on ImportError? -


पायथन में, आयात does_not_exist उठता है importError , और

  आयात मौजूद है  

exist.py :

  आयात does_not_exist  

भी ImportError बढ़ाएगा।

मैं कोड में अंतर कैसे बताऊँ?

मुझे पता है कि एकमात्र तरीका यह है कि क्या टोपीवल मॉड्यूलनम" मौजूद है "अपवाद के संदेश में है या नहीं:

  try: importError के अलावा आयात मौजूद है Exc के रूप में: यदि str (exc) में "मौजूद" है: पास करें: raise  

क्या यह पायथन के आयात के लिए एक सुविधा का अनुरोध हो सकता है? मॉड्यूल नाम के लिए एक चर होने के कारण निश्चित रूप से सुविधाजनक होगा ..


Comments

Popular posts from this blog

iphone - How do I make a UIPickerView in a UIActionSheet -

java - Is there an object like a "Set" that can contain only unique string values, but also contain a count on the number of occurrences of the string value? -