介紹 我得到了一個決議守護行程套接字輸出的函式。我用它來捕捉紅外遙控器上按下的鍵。
def getKey():
while True:
data = sock.recv(128)
data = data.strip()
if (len(data) > 0):
break
words = data.split()
return words[2], words[1]
key = getKey()
print(key)
問題 函式總是回傳單個字串物件
輸出:
1
<class string>
2
<class string>
7
<class string>
問題 如何將所有這些字串物件存盤到單個串列物件中以供進一步使用?
像這樣:
[1,2,7]
<class list>
uj5u.com熱心網友回復:
def getKey():
while True:
data = sock.recv(128)
data = data.strip()
if (len(data) > 0):
break
words = data.split()
return words[2], words[1]
keys = []
keys.append(getKey())
keys.append(getKey())
keys.append(getKey())
print(keys)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/321787.html
