简体   繁体   English

PIL:我在哪里可以找到包含 PILLOW 抛出的所有异常的“异常”class

[英]PIL: Where can I find the “exception” class which contains all the exceptions thrown by PILLOW

After lots of struggle, I am unable to find any module named exception but in the source code on Github , it has a line something like from.exceptions import InvalidFileType, PILReadError .经过一番努力,我找不到任何名为exception的模块,但在Github 的源代码中,它有一行类似于from.exceptions import InvalidFileType, PILReadError Where is this exception module?这个exception模块在哪里? On the other hand, it throws some exceptions which are builtin to Python but I could not find any specific module like in requests.exceptions or some other modules.另一方面,它抛出了一些内置于 Python 的异常,但我找不到任何特定的模块,如requests.exceptions或其他一些模块。

I want to catch and deal with some certain exceptions and when I use Image.open('non existing file') , it throws an FileNotFoundError but the traceback shows no clue of where it came from.我想捕捉并处理一些特定的异常,当我使用Image.open('non existing file')时,它会抛出一个FileNotFoundError但回溯显示它不知道它来自哪里。 Does the Pillow uses exception directly from Exception class?枕头是否直接使用Exception class 中的异常? If yes, then what is that from.exeption in source code?如果是,那么源代码中的from.exeption是什么?

The source you link appears to be to a fork of Pillow.您链接的来源似乎是 Pillow 的一个分支。 The ".exceptions" is referring to the definitions in this file https://github.com/jleclanche/Pillow/blob/master/PIL/exceptions.py , which is in the same folder. “.exceptions”是指此文件https://github.com/jleclanche/Pillow/blob/master/PIL/exceptions.py中的定义,该文件位于同一文件夹中。 There is a __init__.py file in this folder, so any.py file in this folder can be imported as a module (provided you run from within this folder or the folder is included in the PYTHONPATH).此文件夹中有一个__init__.py文件,因此此文件夹中的任何 .py 文件都可以作为模块导入(前提是您在此文件夹中运行或该文件夹包含在 PYTHONPATH 中)。 These exceptions are not currently part of the PILLOW source head.这些异常当前不是 PILLOW 源头的一部分。

To find out more about a particular exception, you can look at all of the attributes for a separate instance of the exception in question.要了解有关特定异常的更多信息,您可以查看相关异常的单独实例的所有属性。 For example, you could do something like this:例如,您可以执行以下操作:

d = Exception('This is a base exception from exceptions')
dir(d)

And then you can see which attributes the exception object has.然后你可以看到异常 object 有哪些属性。 Two useful attributes would be __doc__ and __repr__两个有用的属性是__doc____repr__

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM