栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python根据模板中的MML,批量生成小区脚本

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python根据模板中的MML,批量生成小区脚本

import os
import math
import re

def Generate_Batch_scripts_mml(sourepath, templatepath, parentnode):
    """
    根据模板中的MML,批量生成小区的MML脚本
    template:MML模板,UCELLID=XXX,UNODEB=YYY
    source:原始数据,如导出的CFGMML,主要是用于提取CELLID,以ADD UCELLSETUP中的小区为准
    parentnode:(str)主键从父节点中获取,如CELLID从ADD UCELLSETUP中获取
    return:result增量脚本结果
    """
    # 1.获取主键
    # 环境导出的CFGMML
    soure = open(sourepath, 'r', encoding='utf-8')
    lines1 = soure.readlines()
    keywordlines = []
    for l in lines1:
        if parentnode.strip() in l:
            res = re.search(r'ucellid=d+', l).group()
            keywordlines.append(res)
    # print("keywordlines=", keywordlines, type(keywordlines))
    soure.close()
    # 2.获取模板替换主键并批量生成MML
    # MML模板
    template = open(templatepath, 'r', encoding='utf-8')
    result = open(r"D:pycharm1 Get_MMLresult.txt", 'w+', encoding='utf-8')
    lines2 = template.readlines()
    for l in keywordlines:
        for ll in lines2:
            result.writelines(ll.replace("ucellid=XXX", l.strip()))
        result.writelines('n')
    template.close()
    result.close()
    return result

if __name__ == '__main__':
    # 原数据路径
    path_scr = r"D:pycharm1 Get_MML119.txt"    
    # 功能:根据模板中的MML,批量生成小区脚本
    # MML模板路径
    path_template = r"D:pycharm1 Get_MMLtemplate.txt"
    parentnode = "add ultecell"
    Generate_Batch_scripts_mml(path_scr, path_template, parentnode)
    

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/324368.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号