2017-04-21 49 views
0

我通過定義執行程序函數繼承了類客戶機節點中類NetworkUtility中定義的函數。 你能告訴我,爲什麼它顯示以上錯誤。我對此毫無頭緒。TypeError:executor()不帶參數(給出1)

#!/usr/bin/python 
import socket 
from NetworkUtility import NetworkUtility 
#import json 

HOST = '' # get local machine name by socket.gethostname() 

PORT = 50007    # The same port as used by the server,reserve a port for ur service reserve port 



class ClientNode(object):  #if you don't want to inherit NetworkUtility 


      def executor(): 

       cn1 = NetworkUtility() 
       cn1.setupClientConnection(HOST, PORT) 

       cn1.sendMessage('Client 1: Hello') 
       print cn1.receiveMessage() 
       cn1.endConnection() 

c = ClientNode() 
c.executor() 
+0

如果它是在一個類中,那麼您可能會爲類實例傳遞一個'self' –

回答

1

如果executor()是你ClientNode類的方法,你需要使用:

def executor(self): 

當您運行c.executorc是作爲第一個參數,以你的方法傳遞的類的實例。 self以這種方式代表c

因此,你提供一個論點的事實是正確的,但執行者目前沒有任何論點的事實需要上述更正。

+0

您可以在原始問題中設置代碼的格式,以便我們可以像在實現中一樣看到縮進嗎? – JacobIRR

+0

當我把執行器(自我),然後顯示「socket.error:[Errno 111]連接拒絕」 – arpita

+0

那麼,這意味着我的答案解決了你的問題。現在你有一個新的問題。 – JacobIRR

相關問題