而不是用户必须使用script.py --file c:/stuff/file.txt有一种方法让用户可选地使用--file?所以相反,它看起来像script.py c:/stuff/file.txt但解析器仍然知道用户正在引用--file参数(因为它暗示).
script.py --file c:/stuff/file.txt
--file
script.py c:/stuff/file.txt
python command-line-arguments argparse
argparse ×1
command-line-arguments ×1
python ×1