Pass data as a string to argparse in Python: unrecognized argument

I am trying to parse date as an argument in Python with argparse:

def parsing(parser):
    parser.add_argument("--b", type=str)
    parser.add_argument("--e", type=str)
    return parser

parser = argparse.ArgumentParser()
parser = parsing(parser)
args = parser.parse_args()

I’m trying to execute it with:

python file.py –-b 20100101 –-e 20200120

But I am getting a “unrecognized argument” error. I have also tried removing the type=str, but I get the same error.

C:Usersuserminiconda3libsite-packagesnumpy_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs: 
C:Usersuserminiconda3libsite-packagesnumpy.libslibopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll 

C:Usersuserminiconda3libsite-packagesnumpy.libslibopenblas.WCDJNK7YVMPZQ2ME2ZZHJJRJ3JIKNDB7.gfortran-win_amd64.dll warnings.warn("loaded more than 1 DLL from .libs:" usage: file.py [-h] [--b B] [--e E] file.py: error: unrecognized arguments: –-b 20100101 –-e 20200120

Answer

The error is in this line.

python file.py –-b 20100101 –-e 20200120

one of the ‘-‘ is a different character.

python file.py --b 20100101 --e 20200120

This works.

Leave a Reply

Your email address will not be published. Required fields are marked *