将数据作为字符串传递给 Python 中的 argparse:无法识别的参数
Pass data as a string to argparse in Python: unrecognized argument
我正在尝试使用 argparse:
将日期解析为 Python 中的参数
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()
我正在尝试执行它:
python file.py –-b 20100101 –-e 20200120
但我收到“无法识别的参数”错误。我也尝试删除 type=str
,但我得到了同样的错误。
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
错误在这一行。
python file.py –-b 20100101 –-e 20200120
其中一个“-”是不同的字符。
python file.py --b 20100101 --e 20200120
这有效。
我正在尝试使用 argparse:
将日期解析为 Python 中的参数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()
我正在尝试执行它:
python file.py –-b 20100101 –-e 20200120
但我收到“无法识别的参数”错误。我也尝试删除 type=str
,但我得到了同样的错误。
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
错误在这一行。
python file.py –-b 20100101 –-e 20200120
其中一个“-”是不同的字符。
python file.py --b 20100101 --e 20200120
这有效。