在Python中,除了Ex除e之外,除了Exception之外,e [英] In Python, what's the difference between 'except Exception as e' and 'except Exception, e'

查看:159
本文介绍了在Python中,除了Ex除e之外,除了Exception之外,e的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中,有两种方式可以捕获异常:

In python, there are two ways to catch an exception

except Exception, e:

except Exception as e:

看起来像e是使用的一个。在什么版本的python做这个改变?任何想法为什么?

It seems like 'as e' is the one to use going forward. In what version of python did this change? Any idea why?

推荐答案


此PEP引入了旨在帮助消除Python语法模糊性的更改,简化异常类,简化异常的垃圾回收,并减少Python 3.0中语言的大小。

This PEP introduces changes intended to help eliminate ambiguities in Python's grammar, simplify exception classes, simplify garbage collection for exceptions and reduce the size of the language in Python 3.0.

PEP 3110:捕捉Python 3000中的异常

这篇关于在Python中,除了Ex除e之外,除了Exception之外,e的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆