py_ast.py 文件源码

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

项目:vizgen 作者: uva-graphics 项目源码 文件源码
def get_all_nodes_in_bfs_order(ast_root):
    q = [ast_root]
    result = []

    while len(q) > 0:
        top = q.pop(0)
        result.append(top)

        for field, value in ast.iter_fields(top):
            if isinstance(value, list):
                for item in value:
                    if isinstance(item, ast.AST):
                        q.append(item)
            elif isinstance(value, ast.AST):
                result.append(value)

    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号