V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2017-05-30 09:41:22 +08:00 · 2441 次点击
    这是一个创建于 2526 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2017-05-30 09:58:39 +08:00
    mayne95
        1
    mayne95  
       2017-05-30 09:48:28 +08:00 via Android
    加 html 放到 str 后面
    xiaoyu9527
        2
    xiaoyu9527  
    OP
       2017-05-30 09:49:47 +08:00
    @mayne95 能具体说说怎么放么?

    我如果去掉+'.html' 就可以运行 但是没有'.html'解析不出来
    mseasons
        3
    mseasons  
       2017-05-30 09:51:49 +08:00
    mmpags = [new.url+'_'+str(x)+'.html' for x in range(1,int(nm))]
    katsusan
        4
    katsusan  
       2017-05-30 09:53:04 +08:00
    >>> 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  
       2017-05-30 09:55:48 +08:00 via Android
    [new url+'_'+str(url)+'.html' for x in range (1, int(num))]
    xiaoyu9527
        6
    xiaoyu9527  
    OP
       2017-05-30 09:58:39 +08:00
    搞定了。 竟然后边是生成语句。

    还有这种骚操作
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3265 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:45 · PVG 19:45 · LAX 04:45 · JFK 07:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.