# !/user/bin/python
# -*- coding: utf-8 -*-
"""
"""
import re
import json
from xlog import xwrite
from collections import defaultdict
def defa(prot_h, add_ip):
dic = defaultdict(list)
for key, value in zip(prot_h, add_ip):
dic[key].append(value)
str_json = json.dumps(dic, indent=2, ensure_ascii=False)
print(str_json.replace("[", "").replace(']', '').replace(' ', ''))
def listToJson(keys, lst):
list_json = dict(zip(keys, lst))
str_json = json.dumps(list_json, indent=2) # 将python对象编码成Json字符串
return str_json
def each_line(path):
while True:
arr_str = []
arr_num = []
file_path = path
# p1 = re.compile(r'(.*?)-mlh-INFO-index:(.*),gps(.*)-(.*)')
p1 = re.compile(r'(.*?)-mlh-INFO-(.*)-(.*)')
f = open(file_path, 'r')
for each_line in f:
# xwrite.normal(each_line)
if each_line.strip():
res1 = each_line.replace(' ', '')
res2 = p1.search(res1)
str1 = res2.group(2).split(",", -1)
for i in str1:
a = i.split(":", -1)
xwrite.normal(a)
if len(a) >= 2:
arr_str.append(a[0])
arr_num.append(float(a[1]))
xwrite.normal(arr_str)
xwrite.normal(arr_num)
defa(arr_str, arr_num)
return listToJson(arr_str, arr_num)
if __name__ == '__main__':
print (each_line("/Users/v_qinyuan/Documents/python.project/shop/shuju.txt"))
xwrite.normal(each_line("/Users/v_qinyuan/Documents/python.project/shop/shuju.txt"))
瞎写随笔2---还是各种取值和解析
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
上一篇:品优购实战随笔
下一篇:Netty 框架随笔
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
解析HTTP/2如何提升网络速度HTTP/2
-
随笔写
分类表中一个根类:下有子分类,子分类有子分类,现在要一个分类和它的子分类和子分类都罗列出来,定义一个
DAO System List -
瞎写一气
现在整理一下前几天我们说过的一点点概念两个词,“思想/标准/规范” 和 “实现”。 thought/standard/speci
mvc xml javascript -
脚本练习2---函数
脚本函数的练习
脚本 函数练习