2016-08-19 73 views
-3
while True: 
op_list = [] 

for op in client.longPoll(): 
    op_list.append(op) 

for op in op_list: 
    sender = op[0] 
    receiver = op[1] 
    message = op[2] 

    msg = message.text 
    if msg("help"): 
    receiver.sendMessage('why?') 

if msg("help"): 

TypeError:'str'對象不可調用,任何人都可以幫我嗎?TypeError:'str'對象不可調用di python 2.7

+2

這不能是正確的格式。 「雖然是真的:」什麼?沒有? –

+2

味精(「幫助」)幾乎肯定是你的問題 - message.text是一個字符串,你試圖用參數「help」來調用它。如果你想檢查它是否相等,做msg ==「help」 – James

+1

這段代碼沒有正確縮進,請修復它,以便我們可以專注於你的主要問題。你希望msg(「help」)做什麼? –

回答

0

問題在於第12行。msg是一個文本,顯然它不能被調用。如果你想比較兩個字符串,你應該肯定等於。

if msg == "help": 
    receiver.sendMessage('why?') 
+0

而真: op_list = [] 用於client.longPoll()運算: op_list.append(OP) 用於運算在op_list: 發件人=運[0] 接收機= OP [1] 消息= OP [2] MSG = message.text 如果MSG == 「幫助」: receiver.sendMessage( '?爲何') 如果MSG ==「幫助「: ^ IndentationError:unindent不匹配任何外部縮進級別 –

+0

您可以將此代碼放在mai問題?無法真正理解這裏的縮進。 – Abhinav