我有一个看起来像这样的课程:
class Account(object):
"""A simple bank account"""
def __init__(self, balance=0.0):
"""
Return an account object with a starting balance of *balance*.
"""
self.balance = balance
def withdraw(self, amount):
"""
Return the balance remaining after withdrawing *amount* dollars.
"""
self.balance -= amount
return self.balance
def deposit(self, amount):
"""
Return the amount remaining after depositing *amount* dollars.
"""
self.balance += amount
return self.balance
我会在xyz
中初始化它:
xyz = Account(balance=6000)
xyz.balance
> 6000
我也有一个愚蠢的打印功能:
def thing():
print("I am doing a thing...")
当我尝试在deposit
流程中调用schedule
方法时:
import schedule
# this works
# schedule.every(5).seconds.do(thing)
# this doesn't work
schedule.every(5).seconds.do(xyz.deposit(2300))
while True:
schedule.run_pending()
我收到以下错误:
TypeError:第一个参数必须是可调用的
有什么想法吗?甚至可以在计划流程中调用方法吗?