使用optparse
,我想從我調用add_option()的地方分開選項列表參數列表。我如何將文件打包到文件A中(然後在文件B中解壓縮),這樣才能起作用?該parser_options.append()作爲寫入線條將無法正常工作......如何將參數列表傳遞給Python中的另一個函數?
文件:
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)
*編輯:固定爲使用ojbects
'import file_A'?什麼是控制流程? – StoryTeller
調用'build_parser()'在哪裏? – millimoose
這只是一個片段,因爲有涉及的對象,這將是很多張貼。我只是想說出問題的味道。我需要將這些parser_options從一個對象傳遞到另一個對象。 –