本文共 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/