Created
January 23, 2013 13:04
-
-
Save Lewuathe/4605322 to your computer and use it in GitHub Desktop.
optparseモジュールの使い方 ref: http://qiita.com/items/203a2896f707730f1c28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # まずモジュールのインポート | |
| 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