0

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:\Users\user\miniconda3\lib\site-packages\numpy_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs: 
C:\Users\user\miniconda3\lib\site-packages\numpy\.libs\libopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll 

C:\Users\user\miniconda3\lib\site-packages\numpy\.libs\libopenblas.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
5
  • 1
    Show the full eror message. Commented Mar 16, 2021 at 5:55
  • C:\Users\user\miniconda3\lib\site-packages\numpy_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs: C:\Users\user\miniconda3\lib\site-packages\numpy\.libs\libopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll C:\Users\user\miniconda3\lib\site-packages\numpy\.libs\libopenblas.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 Commented Mar 16, 2021 at 5:57
  • it doesn't give an error in my case Commented Mar 16, 2021 at 6:00
  • Is that EXACTLY how you typed this? Because you would get that error if you passed those arguments as one string: python file.py "--b 20100101 --e 20200120" Commented Mar 16, 2021 at 6:04
  • The difference between the two kinds of dash is most obvious in your comments as displayed on my tablet. With other fonts there's just a slight difference in character length. Commented Mar 16, 2021 at 19:34

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Good eye, by the way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.