def test(pos,target): x, y = pos color = img[x, y] .... - 请问上面这两步有办法简写嘛?
- 假设 pos 很长,都要拆开写入 img[]内,的情况下,类似*参数的写法有嘛?

def test(pos,target): x, y = pos color = img[x, y] .... 1 inhzus Oct 15, 2019 如果没有理解错的话,pos 类型为 tuple,img[x, y] 调用的内置函数为 __getitem__,那就直接 img[pos] 就好了。 如图  |
2 inhzus Oct 15, 2019 @inhzus #1 上一张复制的有些问题,见这张  |
3 JCZ2MkKb5S8ZX9pq OP @inhzus 难怪,我传的是 list,会报错 TypeError: argument must be sequence of length 2 转成 tuple 就可以了,感谢。 |