Issue with continous incrementing of unbroken sequence for a entire working day

Rick Johnson rantingrickjohnson at
Thu Feb 28 20:14:28 CET 2013

On Thursday, February 28, 2013 10:31:58 AM UTC-6, Morten Engvoldsen wrote:
> [...]
> So if the batch has 10 records and last serial number of
> first batch is 10, then when the batch runs second time in
> the same day, how the 'serial_number' will get the value
> of 10 and then continue the serial number for the same
> day,  then for next day again the serial number will start
> from 1.

Well you need "data persistence" between successive runs of the program. That means saving some information to disc. If you don't know how to read and write files with Python, this might be a good time to learn!

But not only must you save the current serial number, you also need to save the current time. Here are the steps your program must do to solve this problem.

1. Run the program.

2. Read the persistent file into memory.

3. Convert the time and serial number into objects (this requires you set up an initial file or have your program logic invent the needed data in the absence of the file).

4. Find out todays date and time (modules: time and datetime would be helpful here).

5. Decide if the last saved date is in the range of "today" (these are rules you need to decide on before hand. Maybe a day is in the range from 12:00am to 11:59pm... up to you).

5a. if the saved serial number was saved "today", then start counting from the saved serial number plus 1.
5b. if however the saved serial number was saved on a previous day, then start counting from 1.

6. Run through all the sales records and do whatever it is you do with them.

7. Overwrite the persistent file with the newly incremented serial number and current time

8. Close the program cleanly.

9. Celebrate another good day of sales (well hopefully)

More information about the Python-list mailing list