How to store a variable when a script is executing for next time execution?

Chris Angelico rosuav at gmail.com
Thu Jun 6 11:56:52 EDT 2013


On Fri, Jun 7, 2013 at 1:54 AM, MRAB <python at mrabarnett.plus.com> wrote:
> On 06/06/2013 16:37, Chris Angelico wrote:
>>
>> On Thu, Jun 6, 2013 at 10:14 PM, Dave Angel <davea at 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



More information about the Python-list mailing list