transform_visitor.py 文件源码

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

项目:SkiRaff 作者: mathiascj 项目源码 文件源码
def __replace_connection(self, id, node):
        """
        Replace name of connection with user-defined id
        :param id: Name to replace with
        :param node: A call node
        """

        newnode = ast.Name(id=id, ctx=ast.Load())
        if len(node.args) != 0:   # Conn given as positional arg
            node.args[0] = newnode
        else:  # Conn given by keyword i.e. "connection = x"
            for keyword in node.keywords:
                if keyword.arg == 'connection'\
                        or keyword.arg == 'f'\
                        or keyword.arg == 'csvfile':
                    keyword.value = newnode

        # Call to fill in line number and indentation information for the new
        # node and its children.
        ast.fix_missing_locations(node)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号