更新时间:2023-11-25 19:59:28
您得到的Exception
相同,因为基本问题是您不能这样做",但详细信息包含在异常实例中,(或较旧的python上的字符串),因此如果您将问题处理为:
You get the same Exception
as your base problem is "You can't do this" but the details are contained in the exception instance, (or in a string on older pythons), so if you handle the problem as:
try:
outfile = open('somename.txt', 'w')
except IOError, e:
print "Not allowed", e
您将获得更多信息. (注:如果您运行的是python 3,则需要在上面的打印内容中添加方括号).
You will get a lot more information. (N.B. if you are running python 3 you will need to add brackets to the print above).
这实际上是一个非常好的设计-您的基本问题是存在问题-如果您愿意的话可以找到更多信息-并且可以以通用的方式处理给定类别的问题.
This is actually incredibly good design - your basic problem is that there is a problem - and you can find out more if you care to - and you can handle a given class of problem in a generalised manner.