を使用してoptparse
、オプション リスト パラメータのリストを add_option() を呼び出す場所から分離したいと考えています。これが機能するように、ファイル A にパッケージ化してからファイル B にアンパックするにはどうすればよいですか? parser_options.append() 行は、書かれているとおりに機能しません...
ファイル A:
import file_b
parser_options = []
parser_options.append(('-b', '--bootcount', type='string', dest='bootcount', default='', help='Number of times to repeat booting and testing, if applicable'))
parser_options.append(('-d', '--duration', type='string', dest='duration', default='', help='Number of hours to run the test. Decimals OK'))
my_object = file_b.B(parser_options)
ファイル B は parser_options を入力として受け取ります。
import optparse
class B:
def __init__(self, parser_options):
self.parser = optparse.OptionParser('MyTest Options')
if parser_options:
for option in parser_options:
self.parser.add_option(option)
*編集: オブジェクトを使用するように修正