Giacomo M Giacomo M - 1 year ago 74
Python Question

Python 2.7.10 how to iterate files creation with different names

I would like to create a different number of files with Python 2.7.10. The number of them is determined by the i index ( range(X) where X is already been defined) and the name should be like :file1,file2,file3,file4...filei. Here what I was writing:

list3 = range(X)
for i in list3:
# (here I want to add the creation process)

Thanks to everyone!!

Answer Source
list3 = range(x)
for i in list3:
    with open("File%i" % i, "w") as myfile:
        #do something
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download