我的Python代码包含以下类
class payment_calculations:
def __init__(self):
self.__interestdatecurrent = str()
return None
def paymentfixed(self, notional, datecouponstart, datecouponend, interestratecurrent, interestratefixed, datecurrent):
当我用
打电话时fixedpayment = payment_calculations.paymentfixed(interestnotional, datecoupon1, datecoupon2, c, interestratefixed, interestdatecurrent)
我看到以下堆栈跟踪
File "C:\Python34\mod_payment_calculation.py", line 83, in coupondatesfixed
fixedpayment = payment_calculations.paymentfixed(interestnotional,datecoupon1,datecoupon2,c,interestratefixed,interestdatecurrent)
TypeError: paymentfixed() missing 1 required positional argument: 'datecurrent'
我从测试文件调用时已经确认这是有效的。但是,当我从模块本身内部运行时,它会失败。有什么想法吗?
答案 0 :(得分:5)
您需要创建该类的实例:
pc = payment_calculations()
fixedpayment = pc.paymentfixed(interestnotional, datecoupon1, datecoupon2, c, interestratefixed, interestdatecurrent)
否则您正在调用未绑定的函数,并且不会自动提供self
参数。相反,interestnotional
值转到self
参数,datecoupon1
转换为notational
参数等等。