Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argparse解析参数的错误/bug for argparse #9

Closed
Rphone opened this issue Mar 12, 2023 · 3 comments
Closed

argparse解析参数的错误/bug for argparse #9

Rphone opened this issue Mar 12, 2023 · 3 comments

Comments

@Rphone
Copy link

Rphone commented Mar 12, 2023

在命令行执行python文件chat_paper.py 输入参数--sort arxiv.SortCriterion.LastUpdatedDate会报错

AttributeError: 'str' object has no attribute 'value'

经过检查发现在chat_paper.py文件中解析--sort参数的代码是

parser.add_argument("--sort", default=arxiv.SortCriterion.Relevance, help="another is arxiv.SortCriterion.LastUpdatedDate")

可能是由于parser.add_argument方法中没有指定type参数,因此python默认将arxiv.SortCriterion.LastUpdatedDate作为str类型解析,则与预期不符,由于arxiv.SortCriterion是枚举类型,因此应该先指定type参数

parser.add_argument("--sort", default=arxiv.SortCriterion.Relevance,type=arxiv.SortCriterion, help="another is arxiv.SortCriterion.LastUpdatedDate")

并在命令行传入枚举类型的值--sort lastUpdatedDate 才能正常运行
请问这是一个bug么?

@Rphone
Copy link
Author

Rphone commented Mar 12, 2023

如有必要我可以提交PR修复这个小问题

@kaixindelele
Copy link
Owner

在命令行执行python文件chat_paper.py 输入参数--sort arxiv.SortCriterion.LastUpdatedDate会报错

AttributeError: 'str' object has no attribute 'value'

经过检查发现在chat_paper.py文件中解析--sort参数的代码是

parser.add_argument("--sort", default=arxiv.SortCriterion.Relevance, help="another is arxiv.SortCriterion.LastUpdatedDate")

可能是由于parser.add_argument方法中没有指定type参数,因此python默认将arxiv.SortCriterion.LastUpdatedDate作为str类型解析,则与预期不符,由于arxiv.SortCriterion是枚举类型,因此应该先指定type参数

parser.add_argument("--sort", default=arxiv.SortCriterion.Relevance,type=arxiv.SortCriterion, help="another is arxiv.SortCriterion.LastUpdatedDate")

并在命令行传入枚举类型的值--sort lastUpdatedDate 才能正常运行 请问这是一个bug么?

多谢提醒,我马上修改一下,我在args里面还是传字符串,然后加上判断筛选出真正的sort,会好一些

@Rphone
Copy link
Author

Rphone commented Mar 12, 2023

在命令行执行python文件chat_paper.py 输入参数--sort arxiv.SortCriterion.LastUpdatedDate会报错

AttributeError: 'str' object has no attribute 'value'

经过检查发现在chat_paper.py文件中解析--sort参数的代码是

parser.add_argument("--sort", default=arxiv.SortCriterion.Relevance, help="another is arxiv.SortCriterion.LastUpdatedDate")

可能是由于parser.add_argument方法中没有指定type参数,因此python默认将arxiv.SortCriterion.LastUpdatedDate作为str类型解析,则与预期不符,由于arxiv.SortCriterion是枚举类型,因此应该先指定type参数

parser.add_argument("--sort", default=arxiv.SortCriterion.Relevance,type=arxiv.SortCriterion, help="another is arxiv.SortCriterion.LastUpdatedDate")

并在命令行传入枚举类型的值--sort lastUpdatedDate 才能正常运行 请问这是一个bug么?

多谢提醒,我马上修改一下,我在args里面还是传字符串,然后加上判断筛选出真正的sort,会好一些

好的,感谢您的辛勤劳动

@Rphone Rphone closed this as completed Mar 12, 2023
@Rphone Rphone reopened this Mar 12, 2023
@Rphone Rphone closed this as completed Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants