如何在Python的OptParser中使用任意數量的參數定義一個選項?在Python中分析任意數量的參數OptParser
我想是這樣的:
python my_program.py --my-option X,Y # one argument passed, "X,Y"
python my_prgoram.py --my-option X,Y Z,W # two arguments passed, "X,Y" and "Z,W"
OptParser的NARGS =選項限制我的定義數字。我該如何做這樣的事情?
parser.add_option("--my-options", dest="my_options", action="append", nargs="*")
這將簡單地採取--my選項後,將其放入列表中?例如。對於情況1,應該是[「X,Y」],對於情況2,應該是[「X,Y」,「Z,W」]。
用OptParser做這件事的方法是什麼?
謝謝。
看到這個問題:http://stackoverflow.com/questions/1025214。 – FMc 2010-07-05 18:39:05