我有一个输入字符串:
result = '"testing","0.8841","642000.0","80.014521","-60.940653","4522126666","1500854400","","1500842014000","name","80.014521","-60.996532","sampledevice","3","name"'
data = result.split("\n")
i = 0
while i < len(data):
i = i +1
dd = data[i].split(',')
print dd
break
并将相应的输出为:
[
'"testing"',
'"0.8841"',
'"642000.0"',
'"80.014521"',
'"-60.940653"',
'"4522126666"',
'"1500854400"',
'""',
'"1500842014000"',
'"name"',
'"80.014521"',
'"-60.996532"',
'"sampledevice"',
'"3"',
'"name"'
]
如何从列表中的每个元素中删除单引号?
将文本视为CSV:
import csv
import StringIO
result = '"testing","0.8841","642000.0","80.014521","-60.940653","4522126666","1500854400","","1500842014000","name","80.014521","-60.996532","sampledevice","3","name"'
print next(csv.reader(StringIO.StringIO(result)))
给你:
['testing', '0.8841', '642000.0', '80.014521', '-60.940653', '4522126666', '1500854400', '', '1500842014000', 'name', '80.014521', '-60.996532', 'sampledevice', '3', 'name']