我有一个带表的数据库:
class KAcc(db.Model):
"""Acc model."""
__tablename__ = 'tacc'
id = db.Column(db.Integer, unique=True, primary_key=True)
bal = db.Column(db.Float(4)) # acc balance
dep = db.Column(db.Float(4)) # deposit
inc = db.Column(db.Float(4)) # income
wth = db.Column(db.Float(4)) # withdraw
我也有这个课程:
class CFin:
def __init__(self, balinit):
"""Initial Balance."""
self.usd = float(balinit)
print("Initial Balance = %.9f" % self.usd)
def deposit(self, d_amount):
"""Down payment in acc."""
self.usd += float(d_amount)
return self.usd
def income(self, v_amount):
"""Income."""
self.usd += float(v_amount)
return self.usd
def withdraw(self, r_amount):
"""Withdraw amount from acc."""
if self.usd - float(r_amount) < 0:
else:
self.usd -= float(r_amount)
return self.usd
def get_balance(self):
"""Final Balance ."""
return self.usd
acc = CFin(10) # initial balance is 10
acc.deposit(2) # first deposit is 2
acc.withdraw(4) # first withdraw is 4
fb = acc.get_balance()
print("Final Balance = %.2f", % fb)
我需要做的是将db表连接到此类以使其正常工作。
我不知道该怎么做,我正在阅读一些与sql有关的如何获取值的内容,但我不知道从哪里开始以及如何获取,我所需要的只是一个提示。