getopt 引数はsys.argvにリストで入ってくる オプション引数の解析はgetopt getoptの第二引数で、「:」が付くのは値をとるとき。 getopt(args, shortopts, longopts=[]) argsには引数 shortoptsは、引数が1文字の時 longoptsは長い引数の時 ex. --help --width 10のような時. ["help","width="]) sample code import getopt import sys try: optlist.args = getopt.getopt(sys.args[1:],"f:") except getopt.GetoptError,pe: print pe.msg sys.exit(0) for opt,args in optlist: if opt in ("-f"): print("
![[python]コマンドライン引数の処理 - okoba0119 @ ウィキ](https://cdn-ak-scissors.b.st-hatena.com/image/square/87187eba81375e12954a570984dcce21a7825ebc/height=288;version=1;width=512/https%3A%2F%2Fads.atwikiimg.com%2Fimg%2Fogimage_setting_s.png)