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

2017-05-30 09:41:22 +08:00
 xiaoyu9527

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

2448 次点击
所在节点    Python
6 条回复
mayne95
2017-05-30 09:48:28 +08:00
加 html 放到 str 后面
xiaoyu9527
2017-05-30 09:49:47 +08:00
@mayne95 能具体说说怎么放么?

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

还有这种骚操作

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/364686

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX