扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
这篇 Python学习教程主要是对 argparse(Python标准库中推荐的命令行解析模块) 进行简要介绍。
note 还有两个其他模块也可以完成相同的任务,分别是 getopt(与C语言中的 getopt() 等效)和已经过时的 optparse。需要注意的是 argparse 也是基于 optparse,因此在用法上非常相似。
概念
让我们通过使用 ls 命令来展示我们将在本 Python学习教程入门中探索的功能类型:
$ ls cpython devguide prog.py pypy rm-unused-function.patch $ ls pypy ctypes_configure demo dotviewer include lib_pypy lib-python ... $ ls -l total 20 drwxr-xr-x 19 wena wena 4096 Feb 18 18:51 cpython drwxr-xr-x 4 wena wena 4096 Feb 8 12:04 devguide -rwxr-xr-x 1 wena wena 535 Feb 19 00:05 prog.py drwxr-xr-x 14 wena wena 4096 Feb 7 00:59 pypy -rw-r--r-- 1 wena wena 741 Feb 18 01:01 rm-unused-function.patch $ ls --help Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. ...
从这四个命令中我们可以学到一些概念:
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流