我是python的新手,我必須在python中編寫我的第一個任務。我保證在完成這一步之後我會學習它,但我現在需要你的幫助。Python:通過引用傳遞套接字
我的代碼,目前看起來是這樣的:
comSocket.send("\r")
sleep(1)
comSocket.send("\r")
sleep(2)
comSocket.settimeout(8)
try:
comSocket.recv(256)
except socket.timeout:
errorLog("[COM. ERROR] Station took too long to reply. \n")
comSocket.shutdown(1)
comSocket.close()
sys.exit(0)
comSocket.send("\r\r")
sleep(2)
comSocket.settimeout(8)
try:
comSocket.recv(256)
except socket.timeout:
errorLog("[COM. ERROR] Station took too long to reply. \n")
comSocket.shutdown(1)
comSocket.close()
sys.exit(0)
errorLog
是另一種方法。我想通過制定一種新方法來重寫這段代碼,以便我可以通過message
,參考socket
,然後return
從套接字收到的信息。
任何幫助?
謝謝:)
通過什麼樣的信息? – SingleNegationElimination
'\ r \ r'是一條消息:)消息將是任意長度的字符串。 –
http://docs.python.org/tutorial/controlflow.html#defining-functions – SingleNegationElimination