當前位置: 首頁>>代碼示例>>Python>>正文


Python ast.slice方法代碼示例

本文整理匯總了Python中ast.slice方法的典型用法代碼示例。如果您正苦於以下問題:Python ast.slice方法的具體用法?Python ast.slice怎麽用?Python ast.slice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ast的用法示例。


在下文中一共展示了ast.slice方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: visit_Slice

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import slice [as 別名]
def visit_Slice(self, node, **kwargs):
        """ df.index[slice(4,6)] """
        lower = node.lower
        if lower is not None:
            lower = self.visit(lower).value
        upper = node.upper
        if upper is not None:
            upper = self.visit(upper).value
        step = node.step
        if step is not None:
            step = self.visit(step).value

        return slice(lower, upper, step) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:expr.py

示例2: visit_Subscript

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import slice [as 別名]
def visit_Subscript(self, node, **kwargs):
        value = self.visit(node.value)
        slobj = self.visit(node.slice)
        result = pd.eval(slobj, local_dict=self.env, engine=self.engine,
                         parser=self.parser)
        try:
            # a Term instance
            v = value.value[result]
        except AttributeError:
            # an Op instance
            lhs = pd.eval(value, local_dict=self.env, engine=self.engine,
                          parser=self.parser)
            v = lhs[result]
        name = self.env.add_tmp(v)
        return self.term_type(name, env=self.env) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:17,代碼來源:expr.py

示例3: visit_Subscript

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import slice [as 別名]
def visit_Subscript(self, subscript: ast.Subscript) -> VisitExprReturnT:
        value, value_actions = self.visit_expr(subscript.value)
        sl, slice_actions = self.visit_slice(subscript.slice)
        ctx = subscript.ctx
        subscript_flattened = ast.Subscript(value=value, slice=sl, ctx=ctx)
        actions = value_actions + slice_actions

        if isinstance(ctx, ast.Load):
            result_id = self.next_symbol_id()
            assign_node = assign(result_id, subscript_flattened)
            return load(result_id), actions + [assign_node]
        elif isinstance(ctx, (ast.Store, ast.Del)):
            return subscript_flattened, actions

        raise NodeNotSupportedError(subscript, "Subscript context not supported") 
開發者ID:NetSys,項目名稱:kappa,代碼行數:17,代碼來源:flatten.py

示例4: visit_slice

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import slice [as 別名]
def visit_slice(self, sl: ast.slice) -> VisitSliceReturnT:
        assert sl not in self._ignored, "Slices cannot be ignored"
        return self.visit(sl) 
開發者ID:NetSys,項目名稱:kappa,代碼行數:5,代碼來源:flatten.py


注:本文中的ast.slice方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。