Python 巨蟒:“;属性错误:';名称空间';对象没有属性“;argparse
我的代码如下所示:Python 巨蟒:“;属性错误:';名称空间';对象没有属性“;argparse,python,Python,我的代码如下所示: parser.add_argument('-i', '--input', help='Input path/to/file.csv', required=True) parser.add_argument('-oh', '--output-html', help='Output path/to/confusion_matrix.html', required=True) parser.add_argument('-oc', '--output-csv', help='Outp
parser.add_argument('-i', '--input', help='Input path/to/file.csv', required=True)
parser.add_argument('-oh', '--output-html', help='Output path/to/confusion_matrix.html', required=True)
parser.add_argument('-oc', '--output-csv', help='Output path/to/confusion_matrix.csv', required=True)
args = parser.parse_args()
....
y_true = pd.Series(true_data, name="Actual")
y_pred = pd.Series(pred_data, name="Predicted")
df_confusion = pd.crosstab(y_true, y_pred)
df_confusion.to_html(args.output-html)
df_confusion.to_csv(args.output-csv)
当我尝试运行它时,会出现以下错误:
df_confusion.to_html(args.output-html)
AttributeError: 'Namespace' object has no attribute 'output'
但是,如果我从
df_confusion.to_html(args.output-html)
到
这是它应该做的。有人能解释为什么它不工作,以及我如何使它与args.output html一起工作吗?默认情况下(即如果您没有提供dest
kwarg toadd_参数
),它会在创建属性时将-
更改为
,因为Python属性不能包含字符-
(事实上,它们可以,但只能通过使用getattr
访问它们)
这意味着您应该将
args.output html
更改为args.output_html
,将args.output csv
更改为args.output_csv
python将args.output html
视为“args.output减去html”,并尝试执行减法。
df_confusion.to_html(args.output)