Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46184
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-05-27 02:27 -0700 |
| Message-ID | <3c99daa0-6f30-4cbf-b107-56021a324f7c@googlegroups.com> (permalink) |
| Subject | How to create new python file with increament number, if doesn't exist? |
| From | Avnesh Shakya <avnesh.nitk@gmail.com> |
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
How to create new python file with increament number, if doesn't exist? Avnesh Shakya <avnesh.nitk@gmail.com> - 2013-05-27 02:27 -0700
Re: How to create new python file with increament number, if doesn't exist? Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-27 10:49 +0000
Re: How to create new python file with increament number, if doesn't exist? Avnesh Shakya <avnesh.nitk@gmail.com> - 2013-05-27 16:30 +0530
Re: How to create new python file with increament number, if doesn't exist? jt@toerring.de (Jens Thoms Toerring) - 2013-05-27 11:13 +0000
csiph-web