<div dir="ltr">Thanks<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 27, 2013 at 4:19 PM, Denis McMahon <span dir="ltr"><<a href="mailto:denismfmcmahon@gmail.com" target="_blank">denismfmcmahon@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Mon, 27 May 2013 02:27:59 -0700, Avnesh Shakya wrote:<br>
<br>
> I want to create a new python file like 'data0.0.5', but if it is<br>
> already exist then it should create 'data0.0.6', if it's also exist<br>
> then next like 'data0.0.7'. I have done, but with range, please give<br>
> me suggestion so that I can do it with specifying range.<br>
<br>
</div>Try and put your description into the sequence of instructions you want<br>
the computer follow.<br>
<br>
For this problem, my sequence of instructions would be:<br>
<br>
1) Find the highest numbered existing file that matches the filename<br>
data0.0.[number]<br>
<br>
2) Create a new file that is one number higher.<br>
<br>
Now the solution is easy. Find the list of filenames in the directory<br>
that match a suitable regular expression, take the numeric value of a<br>
substring of the filename for each file and find the highest, add one to<br>
it, then create the new file name.<br>
<br>
Something like the following (untested) with the relevant imports etc:<br>
<br>
nfn="data0.0."+str(max([int(f[8:])for f in os.listdir(p)if re.match<br>
('^data0.0.[0-9]+$',f)])+1)<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Denis McMahon, <a href="mailto:denismfmcmahon@gmail.com">denismfmcmahon@gmail.com</a><br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br></div>