Python 文件拼接
Posted soloate
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 文件拼接相关的知识,希望对你有一定的参考价值。
# -*- coding:utf-8 -*- import re import csv file = open(‘make_setup.cfg‘, ‘w+‘) with open("tyb.csv", "r", encoding="GBK") as csvfile: # 读取csv文件,返回的是迭代类型 read = csv.reader(csvfile) aa = list(read) file.write(‘[setup_basic] ‘ ‘zip=source/Stock.7z ‘ ‘xml=source/setup.xml ‘ ‘org_exe=setup.bin ‘ ‘[setup_skin] ‘ ‘IDR_BTN_BK_BIG = "source/skin/Install_Btn_Start.png" ‘ ‘IDR_UNCHECK = "source/skin/CHECKBNBK.png" ‘ ‘ ‘) for i in range(len(aa)): pattern = re.compile(r‘d+‘) # 正则表达式,获取数字 sid = pattern.findall(aa[i][1]) sid1 = ‘‘.join(sid) # list转换为str tid = pattern.findall(aa[i][2]) tid1 = ‘‘.join(tid) packageno = pattern.findall(aa[i][0]) a = ‘[‘ + ‘setup_target‘ + str(i + 1) + ‘]‘ + ‘ ‘ + ‘sid=‘ + sid1 + ‘.‘ + tid1 + ‘ ‘ + ‘packageno=‘ + packageno[2] + ‘ ‘ + ‘target=targets/‘ + aa[i][0] + ‘ ‘ file.write(a + ‘ ‘) file.close()
以上是关于Python 文件拼接的主要内容,如果未能解决你的问题,请参考以下文章
PYTHON代码:根据FileRecord和MAP的关系,拼接IBM V7000 精简卷碎片