如何使用python索引路径
在Python中,如何使用计数器(其语法含义)索引路径?例如,我有以下代码:如何使用python索引路径,python,Python,在Python中,如何使用计数器(其语法含义)索引路径?例如,我有以下代码: while i<5: with open("xxx\\xxx\\test(i)","r+") as f: f.write("hello") 而我使用.format()将索引添加到文件名中。还要记住包括i的初始化和增量,并使用写访问权限打开文件 i = 0 while i<5: with open("xxx\\xxx\\test({})".format(i), "w+") a
while i<5:
with open("xxx\\xxx\\test(i)","r+") as f:
f.write("hello")
而我使用.format()
将索引添加到文件名中。还要记住包括i
的初始化和增量,并使用写访问权限打开文件
i = 0
while i<5:
with open("xxx\\xxx\\test({})".format(i), "w+") as f:
f.write("hello")
i += 1
i=0
而我的回答是nx,我的回答是nx
from itertools import count
for i in count(0):
if i >= 5:break
with open(r"test {0}".format(str(i)), "w") as file:
file.write("Hello World")