将清单中的"元件值\t元件位号"分裂为"元件位号\t元件值",每个元件一行
来源:互联网 发布:java面试题及答案2016 编辑:程序博客网 时间:2024/05/22 15:51
在BOM中,清单的格式一般有物料编码,物料描述,元件位号,元件数量,将物料描述简化成一个值,再将这列与元件位号列提取出来,保存到"value+refs.txt"文件中,格式为
元件值\t位号1 位号2 ... 位号n 位号之间的分隔符为1个空格
将下面的脚本复制,保存为"reflist.py"文件,与"value+refs.txt"文件放在同一目录中,操作系统中要先安装有python2(python3未验证),运行此脚本,就会将"value+refs.txt"中的元件按第行一个的格式排列,输出"reflist.txt"文件,此文件就可以直接用作loadBomValue2PCB.bas的输入,将清单中的值导入到PCB中
#!/usr/bin/pythondebug=1logfile="./python_debug.txt"#将"C11-14"转换成"C11,C12,C13,C14"def expandref(inputstr,divider): #result_list.extend("abc")=> ['a','b','c'] f=open(logfile,'w') if debug==1: f.write("expandref() get input: "+ inputstr + "\n") position=inputstr.find(divider) if position==-1: return [inputstr] str1=inputstr[:position] str2=inputstr[position+1:] # get ref prefix in str1 i=0 while str1[i].isalpha(): i=i+1 if i>=len(str1): return [inputstr] prefix1=str1[:i] # get the start number of ref numstart=str1[i:] if numstart.isdigit(): numstart=int(numstart) else: return [inputstr] if debug==1: f.write("expandref(): prefix "+ prefix1 + "\n") f.write("expandref(): numstart "+ str(numstart) + "\n") # get the end number of ref if str2.isdigit(): numend=int(str2) elif str2[:i]==prefix1 and str2[i-1:].isdigit(): numend=int(str2) else: return [inputstr] if debug==1: f.write("expandref(): numend "+ str(numend) + "\n") if numend<=numstart: return [inputstr] ref_l=[] for i in range(numstart,numend+1): ref_l.append(prefix1+str(i)) f.close() return ref_ldef expandrefString(refstring,refdivider,expandseperator): reflist=refstring.strip(refdivider).split(refdivider) returnlist=[] for ref in reflist: if ref=='': continue returnlist.extend(expandref(ref,expandseperator)) return returnlist''' read value+refs.txt file,format like " 10nFC12 C13 " and print to be like " C1210nF C1310nF " '''inputfile="./value+refs.txt"outputfile="./reflist.txt"fin=open(inputfile,'r')fout=open(outputfile,'w')seperator='\t'refSeperator=' 'for line in fin.readlines(): line=line.strip('\r\n').strip('\n').strip(' ').strip('\t') length=len(line) if(length==0): continue sepPositioin=line.find(seperator) valueStr=line[:sepPositioin] refList=expandrefString(line[sepPositioin+1:],' ','-') print("reflist: "+str(refList)) for ref in refList: fout.write(ref+seperator+valueStr+"\n")fin.close()fout.close()
0 0
- 将清单中的"元件值\t元件位号"分裂为"元件位号\t元件值",每个元件一行
- 使用PADS 为元件添加元件参数值
- 元件封装
- 使用元件
- 电感元件
- 电阻元件
- 感光元件
- 线性元件与非线性元件
- 阻容元件标称值
- 元件为基础的设计
- limeJS中的基本编程元件
- 怎么样将元件Value值显示在PCB上
- UML的基础元件之行为元件
- UML的基础元件之说明元件
- gstreamer 之 GstElementFactory ,元件 ,元件状态
- 添加元件库,搜索元件,放置元件
- JMeter--配置元件之参数元件
- 有源元件和无源元件的区别
- 《C++ Primer》一书极不适合我国“国情”
- Mybatis分页插件更新
- FrameLayout margin not working
- c++学习笔记之c/c++两种语言初始化变量区别
- 封装数据库查询学生信息(的增删查改)的方法
- 将清单中的"元件值\t元件位号"分裂为"元件位号\t元件值",每个元件一行
- 《C++面向对象程序设计》 谭浩强 第三章 总结
- 你的论文,你做主—研究生毕业论文的写作过程
- IOS应用开发架构
- iOS 动画Animation详解, UIView动画(UIView属性动画,UIViewTransition动画,UIView Block动画),CALayer动画(CABasicAnima...)
- Python基础教程(第三章)
- linux c 文件重定向 ,很好的代码。
- 今天我住的这边发生一件大事了。
- Python基础教程(第四章)