可能重复:
What's the best way to grab/parse command line arguments passed to a Python script?如何解析Python中的命令行参数?
我希望能够解析命令行参数在我的Python 2.6的程序。
理想情况下,我希望能够处理这些情况:
# Show some help
./myprogram --help
# These are equivalent
./myprogram --block=1
./myprogram -b 1
# This means verbose, and twice as verbose:
./myprogram -v
./myprogram -vv
并以“老的Python版本”,他的意思是每一个发布8天以上版本前。 – 2010-07-13 06:21:16
@Forest - 嘘,我们现在是未来! ;) – tzaman 2010-07-13 06:36:14
随着时间的推移,这个答案变得越来越正确。 – jcdyer 2014-02-28 18:04:46