这是一个创建于 4424 天前的主题,其中的信息可能已经有所发展或是发生改变。
var_list = ['one','two','three']
for i in var_list:
f = open('var_list[i].htm', 'w')
html = '''
<html>
<head><title></title></head>
<body>
<strong><font color=red>Hello World!</font></strong>
</body>
</html>
'''
f.write(html)
f.close()
我想创建三个one.htm, two.htm, three.htm文件出来,但‘var_list[i].htm’明显不是正确的写法,搜了半天也找不到方案特来求教,谢谢先~
4 条回复 • 1970-01-01 08:00:00 +08:00
|
|
1
Brutal 2012-09-12 22:33:00 +08:00 1
f = open('%s.htm' % (i,), 'w')
|
|
|
2
yuelang85 2012-09-12 22:33:12 +08:00
"%s.html"%var_list[i]
|
|
|
3
yuelang85 2012-09-12 22:34:02 +08:00
哦,一楼是对的,没看到楼主用的是for...in
|
|
|
4
durden 2012-09-12 22:43:55 +08:00
|