loop_parallel_ast.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:vizgen 作者: uva-graphics 项目源码 文件源码
def insert_before_parent_list_fixed(node_list, s):
    """
    insert a string before a certain ast node if the node's parent has a field which is a list that contains the node
    """

    for i in range(len(node_list)):
        parent = node_list[i].parent

        for field, value in ast.iter_fields(parent):
            if isinstance(value, list):
                try:
                    index = value.index(node_list[i])
                    value[index:index] = ast.parse(s).body
                except:
                    continue
    return
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号