__init__.py 文件源码

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

项目:py2rb 作者: naitoh 项目源码 文件源码
def visit_Subscript(self, node):
        self._is_string_symbol = False
        name = self.visit(node.value)
        if isinstance(node.slice, (ast.Index)):
            for arg in self._function_args:
                if arg == ("**%s" % name):
                    self._is_string_symbol = True
            index = self.visit(node.slice)
            self._is_string_symbol = False
            return "%s[%s]" % (name, index)
            #return "%s%s" % (name, index)
        else:
            # ast.Slice
            index = self.visit(node.slice)
            if ',' in index:
                """ [See visit_Slice]
                <Python> [8, 9, 10, 11, 12, 13, 14][1:6:2]
                <Ruby>   [8, 9, 10, 11, 12, 13, 14][1...6].each_slice(2).map(&:first)
                """
                indexs = index.split(',')
                return "%s[%s].%s" % (name, indexs[0], indexs[1])
            else:
                return "%s[%s]" % (name, index)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号