获取TypeError:参数:' self'缺少,在与诗歌和CLI合作时
- 我正在使用诗歌和sys.argv。
- 我以OOP的方式编写了代码。
- 当我从CLI运行代码时,我会遇到一个错误,如下所示。
trackback(最近的最新调用):文件“< string>”,第1行,in< module> TypeError:Main()缺少1所需的位置参数:'self'
- 我正在从CLI中进行参数,并将其传递给我的脚本,如下所述。
list_of_ticker = sys.argv[1].split(',')
print(list_of_ticker)
foo = CalculateEtfsYahoo(list_of_ticker)
foo.main()
仅供参考,
该代码才能正常工作,只有在预期输出之后,我就会上述错误。
另外,我还添加了模块。Pakage:class.Function pyproject.toml中的功能,如下所示。
[tool.poetry.scripts] findata =“ investment.parsefindata:calculateEtetfsyahoo.main”
当我用“模块: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'
我不知道如何摆脱此错误。
- I am using poetry and sys.argv.
- I wrote the code in a OOP manner.
- 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'
- 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,
The code is working, only after expected output I am getting above mentioned error.
Also, I have added the module.pakage:class.function in pyproject.toml as shown below.
[tool.poetry.scripts] findata = "investment.ParseFinData:CalculateEtfsYahoo.main"
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 asTraceback (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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果每个人都在工作,而您只想摆脱可以使用的错误
if everyrthing is working and you just want to get rid of the error you could use