multiple arguments in getitem
class A: def __getitem__(self, *args): print(args.__class__, args) class B: def __getitem__(self, args): print(args.__class__, args) def f(*args): print(args.__class__, args) def g(args): print(args.__class__, args) For functions (f or g), we can identify f(1) = f(*(1,)) = f(1,) , but with slicing there is a difference: A()[x] receives raw indexer object x (key or slice), while A()[x,y] receives a tuple (x,y) B()[x] receives (x,), while B()[x,]receives ((x,)) why doesn't python enforce the same identification as for functions? How should I write a generic getitem, where I want to know the numb
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.