本文整理汇总了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)
示例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)
示例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")
示例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)