简体   繁体   English

TypeError: __init__() 在 python 的 argparser 中得到了一个意外的关键字参数 'choices'

[英]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.

相关问题 TypeError: __init__() 得到了一个意外的关键字参数“选择” - TypeError: __init__() got an unexpected keyword argument 'choices' TypeError at '' __init__() 得到一个意外的关键字参数 '' - TypeError at '' __init__() got an unexpected keyword argument '' Python 3.5:TypeError:__ init __()得到了一个意外的关键字参数'nosigint' - Python 3.5 : TypeError: __init__() got an unexpected keyword argument 'nosigint' python请求:TypeError:__ init __()得到一个意外的关键字参数'proxies' - python requests: TypeError: __init__() got an unexpected keyword argument 'proxies' Python openpyxl TypeError:__init __()获得了意外的关键字参数'pivotButton' - Python openpyxl TypeError: __init__() got an unexpected keyword argument 'pivotButton' Telethon Python TypeError:__init__() 得到了一个意外的关键字参数“hash” - Telethon Python TypeError: __init__() got an unexpected keyword argument 'hash' Python Flask - TypeError: __init__() 得到了一个意外的关键字参数“lable” - Python Flask - TypeError: __init__() got an unexpected keyword argument 'lable' Django:__init__() 得到了一个意外的关键字参数“选择” - Django: __init__() got an unexpected keyword argument 'choices' TypeError:__init __()为关键字参数“ choices”获得了多个值 - TypeError: __init__() got multiple values for keyword argument 'choices' 为什么我得到了一个 TypeError: __init__() 在 python sklearn 中得到了一个意外的关键字参数“outer_cv”? - Why I got an TypeError: __init__() got an unexpected keyword argument 'outer_cv' in python sklearn?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM