推荐学习书目
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
Sey0
V2EX  ›  Python

Python 传入参数为字符串,赋值以后自动转为 tuple?有大哥遇到过这奇怪的问题吗

  •  
  •   Sey0 · Mar 24, 2019 · 3453 views
    This topic created in 2630 days ago, the information mentioned may be changed or developed.

    上传不了图片,用文字来说明吧

    self.website = website

    我赋值 website 为'360',self.website 会变成('360',)

    找了很久的原因没有找到,有大哥遇到过吗

    Supplement 1  ·  Mar 25, 2019

    v2没找到上传图的地方 代码:print("self.website:", self.website, 'website:',website);exit(); 直接结果: self.website: ('360',) website: 360

    Supplement 3  ·  Mar 25, 2019
    12 replies    2019-03-25 10:36:40 +08:00
    xiexingjia
        1
    xiexingjia  
       Mar 24, 2019
    贴一下代码呀
    shintendo
        2
    shintendo  
       Mar 24, 2019
    请给一段最短的可复现程序
    ipwx
        3
    ipwx  
       Mar 24, 2019
    你不会写了 self.website, 吧。。。

    后面加个逗号就变成 tuple 了。
    ipwx
        4
    ipwx  
       Mar 24, 2019
    >>> a = 'a',
    >>> a
    ('a',)
    Fulcrum
        5
    Fulcrum  
       Mar 24, 2019 via Android
    不要逗号,就算廖雪峰入门的教程都说了
    shintendo
        6
    shintendo  
       Mar 24, 2019
    这种问题多半是在你认为绝对没问题的地方出了问题,所以代码贴完整很重要
    ipwx
        7
    ipwx  
       Mar 25, 2019
    。。大哥你能不能把完整的代码贴上来?

    贴代码用 gist
    junjieyuanxiling
        8
    junjieyuanxiling  
       Mar 25, 2019 via Android   ❤️ 1
    倒数第二行末尾逗号删了。
    Sey0
        9
    Sey0  
    OP
       Mar 25, 2019
    @junjieyuanxiling - -瞎了眼硬是没看到 一直以为是赋值的问题,感谢大哥
    Trim21
        10
    Trim21  
       Mar 25, 2019 via Android
    感觉需要有一个在括号外 no trailng comma 的规则…不过之前看了看 pylint 和 pycodestyle 都没有类似的规则…
    metamask
        11
    metamask  
       Mar 25, 2019
    self.website =
    这行结尾多了一个逗号
    yushenglin
        12
    yushenglin  
       Mar 25, 2019
    大哥,python 严格严格遵循 PE8 规则,只靠缩进控制,你在 website 后面加了个, ,肯定变元组啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2527 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 15:50 · PVG 23:50 · LAX 08:50 · JFK 11:50
    ♥ Do have faith in what you're doing.