Skip to content

Instantly share code, notes, and snippets.

@Lewuathe
Created January 23, 2013 13:04
Show Gist options
  • Select an option

  • Save Lewuathe/4605322 to your computer and use it in GitHub Desktop.

Select an option

Save Lewuathe/4605322 to your computer and use it in GitHub Desktop.
optparseモジュールの使い方 ref: http://qiita.com/items/203a2896f707730f1c28
# まずモジュールのインポート
import optparse
# parserのメインオブジェクトの作成
parser = optparse.OptionParser()
# 各オプションの設定追加
# この場合だと--debug引数を与えると後で取得する
# optionsオブジェクトのdebugプロパティがTrueになる
# helpは--helpを与えたときに各オプションで表示される
# usageメッセージのこと。
parser.add_option("--debug",
action="store_true",
dest="debug",
help="Debug option")
# optionsが各オプションの値を連想配列としてもっている。
# あとはこれを煮るなり焼くなりする
(options, args) = parser.parse_args()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment