获取TypeError:参数:' self'缺少,在与诗歌和CLI合作时

发布于 2025-01-17 22:35:45 字数 1053 浏览 4 评论 0原文

  1. 我正在使用诗歌和sys.argv。
  2. 我以OOP的方式编写了代码。
  3. 当我从CLI运行代码时,我会遇到一个错误,如下所示。

trackback(最近的最新调用):文件“< string>”,第1行,in< module> TypeError:Main()缺少1所需的位置参数:'self'

  1. 我正在从CLI中进行参数,并将其传递给我的脚本,如下所述。
list_of_ticker = sys.argv[1].split(',')
print(list_of_ticker)

foo = CalculateEtfsYahoo(list_of_ticker)
foo.main()

仅供参考,

  1. 该代码才能正常工作,只有在预期输出之后,我就会上述错误。

  2. 另外,我还添加了模块。Pakage:class.Function pyproject.toml中的功能,如下所示。 [tool.poetry.scripts] findata =“ investment.parsefindata:calculateEtetfsyahoo.main”

  3. 当我用“模块:package:class”

    替换上述第2点时

    [tool.poetry.scripts] findata =“ investment.parsefindata:calculateEtetfsyahoo”

和给出这样的cli命令:poetry run run run findata.main<参数> 然后,我遇到错误 trackback(最近的最新调用):文件“< string>”,第1行,in< module> typeError:calculateEtetfsyahoo()缺少1所需的位置参数:'list_of_ticker'

我不知道如何摆脱此错误。

  1. I am using poetry and sys.argv.
  2. I wrote the code in a OOP manner.
  3. While I am running code from CLI, I am getting an error as shown below.

Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: main() missing 1 required positional argument: 'self'

  1. I am taking argument from CLI and passing it to my script as mentioned below.
list_of_ticker = sys.argv[1].split(',')
print(list_of_ticker)

foo = CalculateEtfsYahoo(list_of_ticker)
foo.main()

FYI,

  1. The code is working, only after expected output I am getting above mentioned error.

  2. Also, I have added the module.pakage:class.function in pyproject.toml as shown below.
    [tool.poetry.scripts] findata = "investment.ParseFinData:CalculateEtfsYahoo.main"

  3. When I am replacing above point 2 with "module.package:class"

    [tool.poetry.scripts] findata = "investment.ParseFinData:CalculateEtfsYahoo"

And giving CLI command like this: poetry run findata.main <argument>
then, I am getting error as
Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: CalculateEtfsYahoo() missing 1 required positional argument: 'list_of_ticker'

I do not know how to get rid of this error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趁微风不噪 2025-01-24 22:35:45

如果每个人都在工作,而您只想摆脱可以使用的错误

import warnings
warnings.filterwarnings("ignore", category=TypeError) #I'm not sure this is the correct category but change it if needed.

if everyrthing is working and you just want to get rid of the error you could use

import warnings
warnings.filterwarnings("ignore", category=TypeError) #I'm not sure this is the correct category but change it if needed.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文