简体   繁体   中英

TypeError: __init__() got an unexpected keyword argument 'type' (argparse issue?)

I'm trying to write a simple script using python3 and I get this error when attempting to force an arg value to be a string. I've searched around but other threads largely involve using Django, etc, which is not what I'm trying to do.

Any help would be greatly appreciated! Thanks in advance.

import argparse

parser = argparse.ArgumentParser('seq_file', type=str, help = 'xyz')
parser.add_argument('sequence_file', type=str, help='xyz')

args = parser.parse_args()

The error I'm getting is:

File "x.py", line y, in <module>
parser = argparse.ArgumentParser('seq_file', type=str, help='xyz')
TypeError: __init__() got an unexpected keyword argument 'type'

What am I doing wrong?

The docs show that argparse.ArgumentParser does not take a type argument.

It looks like you are trying to describe an argument in the constructor to ArgumentParser . Use the add_argument method to do that.

Change

parser = argparse.ArgumentParser('seq_file', type=str, help = 'xyz')

to

parser = argparse.ArgumentParser()
parser.add_argument('seq_file', type=str, help='xyz')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM