TypeError:必须使用loan instance作为第一个参数调用未绑定方法amount()(没有任何内容)

时间:2017-08-11 18:39:28

标签: python-2.7

import datetime


class Loan:
    def __init__(self, principal, rate, date):
        self.p=principal
        self.r=rate
        self.d=date

    def amount(self):
        interest=self.r*self.p
        now=datetime.date.today()
        delta=datetime.timedelta(1)
        then=self.d
        while then <= now:
            print then.strftime("%Y-%m-%d")
            print outstanding 
            outstanding +=interest
            then+=delta


x=Loan
x.p=10000
x.r=0.1/7
x.d=datetime.date.today()-
    datetime.timedelta(5)
x.amount()

我希望得到每个时间间隔的日期和未付金额,但是我收到错误,我检查过去的解决方案并与我的代码交叉检查以确保在实例上调用该方法。我运行代码时得到的错误是:

TypeError:必须使用贷款实例作为第一个参数调用未绑定的方法amount()(没有取而代之)

1 个答案:

答案 0 :(得分:0)

...

{ 
  to: 'All',
  toname: 'Some Name',
  from: 'someaddress@gmail.com',
  fromname: 'Some other Name',
  message: 'A message for all...',
  timestamp: 1502473320,
  imtype: 'msg',
  _id: 'K66iP3dZHbYTfGgK',
  data:
   { readBy:
      [ 'someotheraddress@gmail.com',
        'anotheraddress@gmail.com' ] } 
},
{ 
  to: 'All',
  toname: 'Some Name',
  from: 'someoneelse@gmail.com',
  fromname: 'Some other Name',
  message: 'A message for all...',
  timestamp: 1502473420,
  imtype: 'msg',
  _id: 'K66iP3dZNyNxfGgK',
  data:
   { readBy:
      [ 'someotheraddress@gmail.com',
        'anotheraddress@gmail.com' ] } 
}

...

为构造函数args提供默认值。