在类中创建的函数在直接调用时有效,但在同一个类中调用时不起作用。给了我未定义的全局名称。
我查看了其他帖子,然后检查了我的括号、间距等,但无法看到问题所在。
在下面的代码中,这是有效的:
test1 = srtqualifier(mdlname,datatype,dataconvention,t1)
print (test1.spartSABR())
但这不起作用:
print(test1.makequalifier()) ##NameError: global name 'spartSABR' is not defined
主要代码:
import string
datatype = "Swaption SABR Normal Volatility"
dataconvention = "USD-SIFMA Municipal Swap Index-1W-SWAPTION-PHYSICAL-SEMI-BOND"
mdlname = "IR_SABR"
t1 = 'should-send-back-none'
#datatype = raw_input("Please input Data Type: ")
#dataconvention = raw_input("Please input Data Convention: ")
#modelname = raw_input("Please provide model name: ")
class srtqualifier:
def __init__(self,mdlname,datatype, dataconvention,t1):
self.mdlname = mdlname
self.datatype = datatype
self.dataconvention = dataconvention
self.t1 = t1
self.tempholder = self.dataconvention.split("-")
self.currency = self.tempholder[0]
def spartSABR(self):
secondpartsp = self.tempholder[1].split(" ")
secondpartsp.append(self.tempholder[2])
separator = "_"
secondpart = separator.join(secondpartsp)
secondpart = secondpart.upper()
return secondpart
def modelname(self):
mdname = {'IR_SABR':'SABR','FX_LN':'FXLN','IR_LGM':'LGM','IR_LMM':'LMM','IR_SABR_FX_LN_GC':'SABR_FX_LN_GC','IR_SABR_GC':'SABR_GC','INFLATION_SABR':'SABR_IF'}
return mdname.get(self.mdlname)
慕娘9325324
相关分类