我正在使用一个笔记本,它使用以下语法来设置变量以便稍后在代码中引发异常:
data_format = raise NotImplementedError("Select a data format for your kaggle entry! See docstring of 'assemble_predictors_predictands' for description of data_format.")
但是 VS Code 在运行笔记本时会引发此错误:
data_format = raise NotImplementedError("Select a data format for your kaggle entry! See docstring of 'assemble_predictors_predictands' for description of data_format.")
^ SyntaxError: invalid syntax`
将变量设置为异常的正确方法是什么?
“加注”是一个陈述。尝试将“raise”语句分配给变量,然后只是提到该变量是一个指示器,您应该学习更多 Python 语法、命令式编程和函数
如果您想尝试继续前进而不后退并检查这些概念,您可以将其编写为函数
def data_format():
raise Not implemented error(...)
并像函数一样调用它。