You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python处理SPICE网表:匹配多行跨线的Cell实例

处理SPICE网表中跨多行的Cell实例匹配问题

我用Python处理电子电路SPICE网表时,需要匹配特定名称的Cell实例。SPICE文件中的Cell实例允许通过"+"符号跨多行书写,示例如下:

示例1:

instance_name_here pin1 pin2 pin3
+ pin4 pin5 my_cell_name_here

等价于示例2:

instance_name_here pin1 pin2 pin3 pin4 pin5 my_cell_name_here

网表中共有30个此类Cell,形式涵盖单行、两行,最多可达7行(每个网络后带"+")。目前我仅能匹配单行的实例,无法处理跨多行的情况,尝试使用正则表达式但返回无效结果,寻求解决方案。

我后续实现了一种非正则的处理方法,代码如下:

def get_all_instantiations(cell_name, netlist):
    """返回所有指定Cell实例的字符串列表,完全保留原始格式
    即使用"+"的多行实例会原样返回"""
    cell_instantiations_list = list()
    netlist_lines = netlist.splitlines()
    index = 0
    while index < len(netlist_lines):
        if netlist_lines[index].endswith(cell_name):
            cell_instantiation = netlist_lines[index]
            temp_index = index
            while netlist_lines[temp_index].startswith('+'):
                temp_index -= 1
                cell_instantiation = netlist_lines[temp_index] + "\n" + cell_instantiation
            cell_instantiations_list.insert(0, cell_instantiation)
        index += 1
    return cell_instantiations_list

内容的提问来源于stack exchange,提问作者somerv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 04:45:56