属性错误:';元组';对象没有属性';tb#U框架';在python中的@click.argument中
我有下面的代码,当我运行它时,它会打印出预期的结果,但是在打印的结果之后我遇到了一个属性错误。代码下面包含了错误详细信息属性错误:';元组';对象没有属性';tb#U框架';在python中的@click.argument中,python,attributeerror,python-click,Python,Attributeerror,Python Click,我有下面的代码,当我运行它时,它会打印出预期的结果,但是在打印的结果之后我遇到了一个属性错误。代码下面包含了错误详细信息 import sys import click import pandas as pd from sklearn import metrics @click.command() @click.argument('filename', type=click.Path(exists=True)) def main(filename): df = pd.read_csv(
import sys
import click
import pandas as pd
from sklearn import metrics
@click.command()
@click.argument('filename', type=click.Path(exists=True))
def main(filename):
df = pd.read_csv(filename)
y_test = df["actual"].values
y_pred = df["predicted"].values
print('R Squared: ' + str(metrics.r2_score(y_test, y_pred)))
if __name__ == '__main__':
sys.argv = ['', 'result.csv']
main()
以下是上述代码的完整输出(包括错误的详细信息):
你在谷歌Colab上运行它吗?@mnis我在Jupyter笔记本上运行它。用click.option替换click.argument时效果很好。但我想让它与click.too一起工作。我不明白这段代码如何能够从jupyter笔记本上运行。如何在jupyter笔记本中传递命令行参数?如果您将此代码添加到python文件中,并以
pythonfile.py
@mnis的形式运行它,那么它应该可以工作。我将其保存到.py文件中,并且它没有任何错误。非常感谢。
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
R Squared: 0.8859239452185663
Traceback (most recent call last):
File "C:\Users\mamma\anaconda3\lib\site-packages\click\core.py", line 727, in main
ctx.exit()
File "C:\Users\mamma\anaconda3\lib\site-packages\click\core.py", line 504, in exit
raise Exit(code)
click.exceptions.Exit: 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\mamma\anaconda3\lib\site-packages\click\core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "C:\Users\mamma\anaconda3\lib\site-packages\click\core.py", line 745, in main
sys.exit(e.exit_code)
SystemExit: 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\mamma\anaconda3\lib\site-packages\IPython\core\ultratb.py", line 1151, in get_records
records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
File "C:\Users\mamma\anaconda3\lib\inspect.py", line 1502, in getinnerframes
frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
AttributeError: 'tuple' object has no attribute 'tb_frame'
An exception has occurred, use %tb to see the full traceback.
---------------------------------------------------------------------------
During handling of the above exception, another exception occurred:
SystemExit: 0
C:\Users\mamma\anaconda3\lib\site-packages\IPython\core\interactiveshell.py:3339: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)