![](/img/trans.png)
[英]python - Using argparse, pass an arbitrary string as an argument to be used in the script
[英]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
這行得通。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.