推荐学习书目
› 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 · 3830 views
    This topic created in 2780 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
    xiexingjia
    Mar 24, 2019
    1
    贴一下代码呀
    shintendo
    shintendo
    Mar 24, 2019
    2
    请给一段最短的可复现程序
    ipwx
    ipwx
    Mar 24, 2019
    3
    你不会写了 self.website, 吧。。。

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

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