python - “除了 Exception as e”有什么问题
问题描述
我的代码出现以下错误。任何人都可以帮助我吗?
代码如下
def askforinteger():
while True:
try:
a = int(input("enter an integer")
except Exception as e :
print("there is a error of", e)
else:
print("person has entered correct input")
break
finally:
print("clsoe this issue")
错误如下
File "<ipython-input-5-234fd49c196d>", line 5
except Exception as e :
^
SyntaxError: invalid syntax
解决方案
你有错误语法:
您忘记在属性中添加括号
希望这会解决它试试这个:
def askforinteger():
while True:
try:
a = int(input("Enter a number: "))
print("person has entered correct input")
except Exception as e :
print("there is a error of", e)
break
finally:
print("clsoe this issue")
推荐阅读
- python - 为什么我的 DataFrame 将添加内容复制到特定列?
- android - 即时运行不适用于运行 android 9.0 的 Google 像素 2xl
- javascript - 深度克隆对象不运行功能 - javascript
- r - 在没有错误的并行循环中附加 CSV
- python - Django-admin TypeError: __init__() 得到了一个意外的关键字参数“allow_abbrev”
- javascript - TypeError:更新后无法读取未定义的属性“任何”
- java - 从 CSV 文件读取时出现 NumberFormatException 错误
- spring - Spring MVC Jackson 消息转换器:“冲突的设置器定义”
- php - 在 PHP 脚本中使用 sys_get_temp_dir 将文件保存在临时目录中
- elasticsearch - ELK-Stack:使用 Logstash 仅解析来自 Syslog 的 IP/MAC