1
Green Tree Snakes给出了一个使用ExtSlice
的an example:什么时候在Python的AST中使用ExtSlice节点?
>>> parseprint("l[1:2, 3]")
Module(body=[
Expr(value=Subscript(value=Name(id='l', ctx=Load()), slice=ExtSlice(dims=[
Slice(lower=Num(n=1), upper=Num(n=2), step=None),
Index(value=Num(n=3)),
]), ctx=Load())),
])
然而,这句法不会在交互式Python外壳工作:
>>> foo = range(10)
>>> foo[1:2,3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not tuple
任何人有一个想法如何使用此功能?
相关讨论:
你期望'foo [1:2,3]'是什么? – zondo