推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
JCZ2MkKb5S8ZX9pq
V2EX  ›  Python

问个列表转化的小问题

  •  
  •   JCZ2MkKb5S8ZX9pq · Oct 15, 2019 · 2300 views
    This topic created in 2536 days ago, the information mentioned may be changed or developed.
    def test(pos,target):
    	x, y = pos
    	color = img[x, y]
        ....
    
    • 请问上面这两步有办法简写嘛?
    • 假设 pos 很长,都要拆开写入 img[]内,的情况下,类似*参数的写法有嘛?
    inhzus
        1
    inhzus  
       Oct 15, 2019
    如果没有理解错的话,pos 类型为 tuple,img[x, y] 调用的内置函数为 __getitem__,那就直接 img[pos] 就好了。
    如图 ![image.png]( https://i.loli.net/2019/10/15/gTp1e3W8oaDAdvu.png)
    inhzus
        2
    inhzus  
       Oct 15, 2019   ❤️ 1
    @inhzus #1 上一张复制的有些问题,见这张 ![image.png]( https://i.loli.net/2019/10/15/RkbDN6miOwptyzH.png)
    JCZ2MkKb5S8ZX9pq
        3
    JCZ2MkKb5S8ZX9pq  
    OP
       Oct 15, 2019
    @inhzus 难怪,我传的是 list,会报错 TypeError: argument must be sequence of length 2
    转成 tuple 就可以了,感谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2312 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:32 · PVG 08:32 · LAX 17:32 · JFK 20:32
    ♥ Do have faith in what you're doing.