2017-05-11 5 views
1

I는 다음과 같습니다 클래스가 있습니다일정 작업 내에서 메소드를 호출 할 수 없습니다

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 

가 나는 또한 바보 같은 인쇄 기능이를 : 내 scheduledeposit 메소드를 호출하려고

def thing(): 
    print("I am doing a thing...") 

흐름 :

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: the first argument must be callable

어떤 아이디어? 일정 흐름 내에서 메소드를 호출 할 수 있습니까?

답변

2

schedule에 익숙하지 않지만, do()wants과 같이 호출 가능, 즉 메서드로 보입니다. xyz.deposit 메서드와 2300 메서드가 아니라 xyz.deposit(2300)의 반환 값을 지정합니다. 시도해보십시오.

schedule.every(5).seconds.do(xyz.deposit, 2300) 
+0

굉장합니다. 감사! 그러나 입력 변수가없는 메소드에서이 작업을 수행 할 수는 없었지만 ... 속성에 액세스하려고한다고 생각합니다. 생각? – emehex

+1

나는 최소한의 예를 시도했고 그것은 나를 위해 일했다. 정확히 무엇을하고 있는지 게시하십시오. – jpkotta

+0

내 방법에 '자기'를 잊어 버렸습니다. 그렇지 않으면 작동합니다. 확인해 주셔서 감사합니다. – emehex

관련 문제