On Fri, Jun 7, 2013 at 1:54 AM, MRAB <pyt...@mrabarnett.plus.com> wrote: > On 06/06/2013 16:37, Chris Angelico wrote: >> >> On Thu, Jun 6, 2013 at 10:14 PM, Dave Angel <da...@davea.name> wrote: >>> >>> If you're planning on having the files densely populated (meaning no gaps >>> in >>> the numbering), then you could use a binary search to find the last one. >>> Standard algorithm would converge with 10 existence checks if you have a >>> limit of 1000 files. >> >> >> Or, if you can dedicate a directory to those files, you could go even >> simpler: >> >> dataFile = open('filename0.0.%d.json'%len(os.listdir()), 'w') >> >> The number of files currently existing equals the number of the next file. >> > Assuming no gaps.
Which is also a stated assumption of the binary search. The only additional assumption of the file-count method is that there be no other files in that directory. ChrisA -- http://mail.python.org/mailman/listinfo/python-list