python - Python中的意外名称错误
问题描述
>>> e = 'e'
>>> e
'e'
>>> try: raise Exception
except Exception as e:
e = 'e'
a = 'a'
>>> e
Traceback (most recent call last):
File "<pyshell#333>", line 1, in <module>
e
NameError: name 'e' is not defined
>>> a
'a'
我以前没有注意到这种行为。为什么使用变量作为 try-except 别名会使其失去先前的定义?
解决方案
推荐阅读
- html - 如何在选择下拉列表中应用占位符以及角度 6 中的 [ngmodel]?
- java - 进度条完成后调用方法
- flutter - 如何全局更改 OutlineButton 的边框颜色和宽度?
- elasticsearch - 如何在 Grafana 中重置“警报”状态
- python - Python 链表实现和对象建模
- javascript - 如何在Joi中的一个值上验证具有两个最大条件的对象?
- django - 页面正在打开,但当我使用 {% for i in kitty_list %} 时搜索不起作用,但如果是 {% for i in kitty %},则出现 NoReverseMatch 错误
- apache-kafka - KSQL 状态是否可以从 Kafka Streams 应用程序中查询?
- android - 将 Serializable 用作 Android 导航组件的深层链接参数
- c# - 如何从不同项目文件夹的输出目录访问运行时中的文件