How to create new python file with increament number, if doesn't exist?
Avnesh Shakya
avnesh.nitk at gmail.com
Mon May 27 05:27:59 EDT 2013
hi,
I want to create a new python file like 'data0.0.5', but if it is already exist then it should create 'data0.0.6', if it's also exist then next like 'data0.0.7'. I have done, but with range, please give me suggestion so that I can do it with specifying range.
I was trying this way and it's working also..
i = 0
for i in range(100):
try:
with open('Data%d.%d.%d.json'%(0,0,i,)): pass
continue
except IOError:
edxCorrectDataFile = file('Data%d.%d.%d.json'%(0,0,i,), 'a+')
break
But here I have defined range 100, Is it possible without range it create many required files?
Thanks
More information about the Python-list
mailing list