Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
比较两个箱码,和盒码重复的条目
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# file: contrast_Barcode.py
import xml.etree.ElementTree as ET
import os
import sys
def Barcode_info(Barcode_info_filename):
tree = ET.ElementTree(element=None, file='%s.xml'%Barcode_info_filename)
box = []
mbox = []
for elem in tree.iter(tag='Code'):
if elem.attrib['packLayer']=='2':
box.append(elem.attrib['curCode'])
if elem.attrib['packLayer']=='1':
mbox.append(elem.attrib['curCode'])
return box, mbox
def print_repeat(box_1, box_2):
return [ str(k)+" "+str(box_1.count(k)) for k in box_1 if k in box_2 ]
os.chdir('C:/Users/fbigun/Desktop/xml')
f1 = open('box_tmp.txt', 'a')
f2 = open('mbox_tmp.txt', 'a')
box_1, mbox_1 = Barcode_info('1')
box_2, mbox_2 = Barcode_info('2')
print('箱子条形码 重复次数', file=f1)
f1.write(os.linesep.join( print_repeat(box_1, box_2) ) )
print('盒子条形码 重复次数', file=f2)
f2.write(os.linesep.join( print_repeat(mbox_1, mbox_2) ) )
f1.close
f2.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.