分裂我有这样的码的一部分的字符串:合并通过空间在Python
for line in response.body.split("\n"):
if line != "":
opg = int(line.split(" ")[2])
opc = int(line.split(" ")[3])
status = int(line.split(" ")[5])
if command == 'IDENTIFY':
if opg==opcodegroupr and opc==opcoder:
if status=="0":
IEEEAddrRemoteDev = line.split(" ")[6:14]
ret['success'] = "IDENTIFY: The value is %s " % (IEEEAddrRemoteDev)
self.write(tornado.escape.json_encode(ret))
self.finish()
变量“线”是这样的,例如:
1363011361 2459546910990453036 157 0 17 0 209 61 0 0 0 0 0 0 0 0 0 0 0 0 0 201
我将例如采取字段从6到14并且“合并”彼此以像整个字符串那样打印IEEEAddrRemoteDev。
这是
IEEEAddrRemoteDev = line.split(" ")[6:14]
正确的方法是什么?如果我写
print IEEEAddrRemoteDev
我没有得到任何东西。
有问题的话...
我不知道为什么你没有得到任何东西,但加盟的字符串是这样的:'“”。 join(line.split(“”)[6:14])' – hughdbrown 2013-03-11 14:31:33
你永远不会得到任何输出的原因是,如果status ==“0”:'永远不是真的,因为你将它转换为int。看到我的回答 – 2013-03-11 14:40:23