博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用正则获取txt订单数据并写入excel表
阅读量:2152 次
发布时间:2019-04-30

本文共 2442 字,大约阅读时间需要 8 分钟。

import reimport xlwt#order_info=[{"81502804":[{"38":{"#03":80,"#11":40,"#30":45,"#50":65,"#70":55,"#76":45}}]},    #{"81502805":[{"38":{"#76":35,"#32":35,"#60":35}}]}] # 模板class ProcessTxtOrder(object):     def __init__(self,txt_path,write_path):        self.txt_path=txt_path        self.write_path=write_path            def read_txt(self):        try:            f=open(self.txt_path,"r")            self.content_line=f.readlines()            f.close()        except Exception as ret:            print(ret)                def handle_content_line(self):        self.new_order=[]        for i in self.content_line:            size=re.findall(r"4[0246]{1}\s4[0246]{1}\sFREE\s",i)             style=re.findall(r"(C[VHPL]{1}-[0-9]{8})",i)            col=re.findall(r"([0-9]{2}\))",i)            if style!=[] or col!=[]or size!=[]:                if size!=[]:                    self.new_order.append(size[0])                elif style!=[]:                    self.new_order.append(style[0])                    if col!=[]:                        self.new_order.append(col[0])                        quantity=re.findall(r'[0-9]+\)\s([0-9]+|\s|-)\s([0-9]+|\s|-)',i)                        if quantity!=[]:                            self.new_order.append(quantity[0])                            #print("type of quantity:",type(quantity[0]))                            #print(quantity)                elif col!=[]:                        self.new_order.append(col[0])                        quantity=re.findall(r'[0-9]+\)\s([0-9]+|\s|-)\s([0-9]+|\s|-)',i)                        if quantity!=[]:                            self.new_order.append(quantity[0])                            #print("type of quantity:",type(quantity[0]))                            #print(quantity)                 else:                    print("出错了")        return  self.new_order              def write_processed_result(self):        try:            f=open(self.write_path,"w")            f.write(str(self.new_order))            f.close()        except Exception as ret:            print(ret)                def run(self):        self.read_txt()        self.handle_content_line()        self.write_processed_result()        class MakeListDictNestedFormat(object):    def __init__(self,order_list):        self.order_list=order_list            def transform_order_list_into_nested_format(self):        self.general_list=[]        dict_col={
} i=0 while i

转载地址:http://pzswb.baihongyu.com/

你可能感兴趣的文章
Logistic regression 为什么用 sigmoid ?
查看>>
Logistic Regression 为什么用极大似然函数
查看>>
SVM 的核函数选择和调参
查看>>
LightGBM 如何调参
查看>>
用 TensorFlow.js 在浏览器中训练神经网络
查看>>
cs230 深度学习 Lecture 2 编程作业: Logistic Regression with a Neural Network mindset
查看>>
梯度消失问题与如何选择激活函数
查看>>
为什么需要 Mini-batch 梯度下降,及 TensorFlow 应用举例
查看>>
为什么在优化算法中使用指数加权平均
查看>>
什么是 Q-learning
查看>>
用一个小游戏入门深度强化学习
查看>>
如何应用 BERT :Bidirectional Encoder Representations from Transformers
查看>>
5 分钟入门 Google 最强NLP模型:BERT
查看>>
强化学习第1课:像学自行车一样的强化学习
查看>>
强化学习第2课:强化学习,监督式学习,非监督式学习的区别
查看>>
强化学习第3课:有些问题就像个赌局
查看>>
强化学习第4课:这些都可以抽象为一个决策过程
查看>>
强化学习第5课:什么是马尔科夫决策过程
查看>>
强化学习第6课:什么是 Crossentropy 方法
查看>>
强化学习第7课:交叉熵方法的一些局限性
查看>>