python - Try中Python中的语法错误,除了块
问题描述
我正在运行别人的代码:
./run_me.sh
Traceback (most recent call last):
File "train.py", line 13, in <module>
import options
File "/Users/test/Desktop/lang-emerge/options.py", line 44
except IOError, msg: parser.error(str(msg));
^
SyntaxError: invalid syntax
我尝试修改 except 块,但再次出现错误:
./run_me.sh
Traceback (most recent call last):
File "train.py", line 13, in <module>
import options
File "/Users/test/Desktop/lang-emerge/options.py", line 44
except: IOError, msg: parser.error(str(msg));
^
SyntaxError: only single target (not tuple) can be annotated
错误的代码是:
try: parsed = vars(parser.parse_args());
except: IOError, msg: parser.error(str(msg));
不知道如何解决错误?msg 是 python try/except 块中的关键字。
使用修改后的代码,IOError as msg:
我得到:
./run_me.sh
Traceback (most recent call last):
File "train.py", line 13, in <module>
import options
File "/Users/test/Desktop/lang-emerge/options.py", line 44
except: IOError as msg: parser.error(str(msg));
^
SyntaxError: invalid syntax
解决方案
except: IOError as msg: parser.error(str(msg));
你有不必要的冒号。你应该删除它:下面的代码是正确的。
except IOError as msg: parser.error(str(msg));
推荐阅读
- mysql - 在日期列中使用 varchar 数据类型按日期分组
- ios - 将 JSON 数组解包成 Swift 对象
- arrays - 分配数组 [ArraySize] 是否正确?这里 ArraySize 是用户给出的输入
- python - 带有 tf.hessians 的 keras 模型的 hessian 矩阵
- javascript - 尝试获取特定数据但得到“无法读取 XMLHttpRequest.xhr.onreadystatechange 处未定义的属性 '0'”
- angular - 在 Angular 中使用 Javascript 访问 png 元数据
- r - 如何让 R 为 A 列中的每个唯一变量返回 B 列的最大值?
- asp.net - IIS 请求在 BeginRequest - IIS Web 代码中被触发
- c# - 依赖注入自定义文件提供程序以进行运行时编译
- rest - Docusign REST API:使用 Microsoft Flow 的 JWT Grant 实现 OAuth 身份验证