python - NoneType 对象没有属性
问题描述
def 预测(银行,年份):
类银行:
def __init__(self, name):
self.name = name
self.mark_cap = 0
self.acc_list = []
self.age = 0
def lend(self, principal, ann_inc):
self.mark_cap -= principal
def forward_year(self):
self.age += 1
def back_year(self):
if self.age == 0:
self.age = 0
self.age -= 1
def show_high(self):
print(Bank.acc_list[0])
班级帐号:
def __init__(self, ID, password):
self.ID = ID
self.password = password
if len(password) < 5:
print('Password must be at least 5 characters')
self.amount = 0
self.interest = 0.0175
self.acc_org = [ID, password, self.amount, self.interest]
def deposit(self, x):
self.amount += x
self.acc_org[2] = self.amount
def withdraw(self, y):
self.amount -= y
self.acc_org[2] = self.amount
def threshold(self):
if self.amount >= 1000000:
self.interest = 0.02
def comp_int(self, n):
self.threshold()
self.amount *= (1 + self.interest)**n
self.acc_org[2] = self.amount
def show_amount(self):
print(self.amount)
def add_2_bank(self, name):
bank_name = name
bank_name.acc_list.append(self.acc_org)
X = Bank('中国银行')
Account1 = Account('12345', '12345') Account1.deposit(200) Account1.comp_int(2) Account1.add_2_bank(X)
X.show_high()
我得到的错误是我的“银行”对象(X)没有属性 acc_list()。有人请帮助我。
解决方案
在show_high
方法中,修改Bank.acc_list
为self.acc_list
。只能使用静态属性,例如Bank.*
.
推荐阅读
- lua - Lua:如何通过将字符串列入黑名单来阻止 io 库?和沙盒困境
- matlab - Matlab欧拉法
- maven - docker multistage spring boot build pom + 内部依赖
- javascript - 有什么方法可以告诉 Flow getElementById() 返回的 HTMLElement 不能为空?
- c++ - 多次打印出整个数组
- javascript - 使用 Grid fs 在 mongo 数据库中存储数千个图像文件,这是个好主意吗?
- python - 计算字符串中的子字符串,不包括一个字符串
- apache - 如何在 apache 上模拟 500 http 错误
- python - 不知道为什么我没有收到通知
- sql - Oracle SQL比较列值并选择最大值在第1列中的行