我在__main__.py
文件中有以下代码:
from argparse import ArgumentParser
from pwpcore.job import Job, job
from GlobalMacroGen import GlobalMacroGen
parser = ArgumentParser(
description=GlobalMacroGen.__doc__,
conflict_handler="resolve",
parents=[job.parser])
parser.add_argument('--wikiPage', default="http://wiki.noco.corp/display/PD/Global+Macro+Generator")
parser.add_argument('--file', help='Global Macro CSV to generate Notional
parser.add_argument('--USDNotionals', nargs='+')
args = parser.parse_args()
with Job(GlobalMacroGen.__name__, args) as j:
loader = GlobalMacroGen(j)
loader.load_file(args.file)
在我的GlobalMacroGen
类中,我有这个:
import petl as etl
from pwpcore.file_loader import FileReader
from pwpcore.logging import Logger
class GlobalMacroGen(object):
"""Extracts Global Macro file and transforms quantity to use Notional USD for specific symbols
"""
def __init__(job):
self.job = job
def load_file(self, file):
file_reader = FileReader(self.job)
with file_reader.open(file) as file_processor:
global_macro = file_reader.read(file_processor)
USD_Notionals = self.transform(global_macro)
return etl.tocsv(USD_Notionals)
def generate_symbols(self, args):
return args.USDNotionals
def transform(self, data):
pass
运行此命令时,--USDNotional
的args应该吸收一堆字符串并从中产生一个列表:
参数:
word word otherWord moreWords
,
将产生:
[word, word, otherWord, moreWords]
我该如何在班级内部获取此列表?像调用args.USDNotionals
一样简单吗?