[英]TypeError: __init__() got an unexpected keyword argument 'choices' in python's argparser
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-u', '--url',help='Passing one url')
parser.add_argument('-t', '--type', action='store_true',help='To download pages/posts', choices=['pages', 'posts'])
args = parser.parse_args()
url = args.url
if args.type == "pages":
url_link = url + "/wp-json/wp/v2/pages/?per_page=100"
if args.type == "posts":
url_link = url + "/wp-json/wp/v2/posts/?per_page=100"
If the user chooses "pages" then the pages url_link should be used.如果用户选择“页面”,则应使用页面 url_link。 If they choose "posts", it should pass "posts" url_link.
如果他们选择“posts”,它应该通过“posts”url_link。 If they don't choose anything, an error handling of "Please choose your type" in --type error.
如果他们不选择任何内容,则会在 --type 错误中对“请选择您的类型”进行错误处理。
I tried doing this but it says choices in unknown.我试过这样做,但它说选择未知。 Weird... Please help.
奇怪...请帮忙。
Ps - This is my first question on StackOverFlow. Ps - 这是我在 StackOverFlow 上的第一个问题。 Forgive me if I made any mistake and please comment what to correct.
如果我犯了任何错误,请原谅我,请评论要更正的内容。
It doesn't make sense to specify choices when the action is 'store_true'
.当操作为
'store_true'
时,指定选项是没有意义的。
Perhaps you meant:也许你的意思是:
parser.add_argument('-t', '--type', help='To download pages/posts',
choices=['pages', 'posts'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.