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

求助大佬我这句话怎么改才能对 Python 语句

  •  
  •   xiaoyu9527 · May 30, 2017 · 2926 views
    This topic created in 3290 days ago, the information mentioned may be changed or developed.

    str(x) for x in range(1,int(nm))

    mmpags = [new.url+'_'+str(x) for x in range(1,int(nm))+'.html']
    

    TypeError: unsupported operand type(s) for +: 'range' and 'str' 求助 我这里写的哪里有问题 str(x) for x in range(1,int(nm)) 我这个应该怎么写 nm 是页面最大数 1 到 nm

    6 replies    2017-05-30 09:58:39 +08:00
    mayne95
        1
    mayne95  
       May 30, 2017 via Android
    加 html 放到 str 后面
    xiaoyu9527
        2
    xiaoyu9527  
    OP
       May 30, 2017
    @mayne95 能具体说说怎么放么?

    我如果去掉+'.html' 就可以运行 但是没有'.html'解析不出来
    mseasons
        3
    mseasons  
       May 30, 2017
    mmpags = [new.url+'_'+str(x)+'.html' for x in range(1,int(nm))]
    katsusan
        4
    katsusan  
       May 30, 2017
    >>> newurl = 'v2ex.com'
    >>> mmpages = [newurl + '_' + str(x) + '.html' for x in range(5)]
    >>> mmpages
    ['v2ex.com_0.html', 'v2ex.com_1.html', 'v2ex.com_2.html', 'v2ex.com_3.html', 'v2ex.com_4.html']
    justtery
        5
    justtery  
       May 30, 2017 via Android
    [new url+'_'+str(url)+'.html' for x in range (1, int(num))]
    xiaoyu9527
        6
    xiaoyu9527  
    OP
       May 30, 2017
    搞定了。 竟然后边是生成语句。

    还有这种骚操作
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3055 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 15:02 · PVG 23:02 · LAX 08:02 · JFK 11:02
    ♥ Do have faith in what you're doing.