Created
November 12, 2014 14:28
-
-
Save fbigun/7e0a2f23356694446af9 to your computer and use it in GitHub Desktop.
比较两个箱码,和盒码重复的条目
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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