我的代码是这样的:
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print "received message:", data
这是我的输出:
$$359138030323187,7001,2000/00/00,00:00:00,0.00000,0.00000,0.0,0,0,0,0,0.0,0,0.0,0,0,0,0.0,12.2,11,4,0.0##
我只想显示第5和第6个数据列。像这样:
The lat is 0.00000
The long is 0.00000
我哪里错了?
答案 0 :(得分:1)
您需要split您的数据:
split_data = data.split(",")
print("The lat is {}".format(split_data[5]))
print("The long is {}".format(split_data[6]))