Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40152 > unrolled thread

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

Started byMorten Engvoldsen <mortenengv@gmail.com>
First post2013-02-28 20:00 +0100
Last post2013-03-01 07:52 +1100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Issue with continous incrementing of unbroken sequence for a entire working day Morten Engvoldsen <mortenengv@gmail.com> - 2013-02-28 20:00 +0100
    Re: Issue with continous incrementing of unbroken sequence for a entire working day John Gordon <gordon@panix.com> - 2013-02-28 19:23 +0000
      Re: Issue with continous incrementing of unbroken sequence for a entire working day Chris Angelico <rosuav@gmail.com> - 2013-03-01 07:52 +1100

#40152 — Re: Issue with continous incrementing of unbroken sequence for a entire working day

FromMorten Engvoldsen <mortenengv@gmail.com>
Date2013-02-28 20:00 +0100
SubjectRe: Issue with continous incrementing of unbroken sequence for a entire working day
Message-ID<mailman.2663.1362078015.2939.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

Hi,
thanks for youe suggestion. I think i will go for your second option:

# Runs this loop until killed
while True
<do some stuff: clean serial_number, if day changed, calculate salesrecord
etc.>

serial_number = salesrecord(serial_number)


But, if i save the serial_ number value in file, then how  will it decide
to reset the serial number to '1' when the batch  runs on next working day.
What condition can be good, so that next day when the batch runs, it will
know it has to reset the value 1.  Also my batch will not automatcilly run
whole day, this is user's decision how many times he wants to run the batch
in a day. Can you elebrate more how can i do that ...

On Thu, Feb 28, 2013 at 6:43 PM, Vytas D. <vytasd2013@gmail.com> wrote:

> Hi,
>
> If you want to have one program running forever and printing
> sales_records, you would do (one of the possibilities) something like this:
> def salesrecord(serial_number):
>
>     for i in salesrecord:
>
>         print first_sales_record
>         serial_number += 1
>         print serial_number
>     return serial_number
>
> if __name__ == '__main__':
>     serial_number = 1
>
>     # Runs this loop until killed
>     while True
>         <do some stuff: clean serial_number, if day changed, calculate
> salesrecord etc.>
>
>         serial_number = salesrecord(serial_number)
>
> If you want to run your script so it finishes and then saves last value of
> serial_number, so you can pass it to your script when it runs next time,
> you should save the value to some file and read that file on every start of
> your program.
>
> Vytas
>
>
> On Thu, Feb 28, 2013 at 4:31 PM, Morten Engvoldsen <mortenengv@gmail.com>wrote:
>
>> Hi team,
>> I need to run a batch of sales records and  the batch has serial_number
>> filed to store the serial number of the sales record. The serial number
>> should be set to  1 everyday when the batch runs first time in a day and
>> the maximum serial number could be 1000.
>>
>> So when the batch runs first time in a day and if it has 10 records, so
>> the last serial number will be 10. And when the batch runs 2nd time in same
>> day, the serial number should start from 11.  In this way serial_number
>> will increment as an unbroken series throughout the entire working day. The
>> next day when the batch runs first time the serial number will reset to 1.
>>
>> Now this could be sample code how the program can count the sequence for
>> a batch:
>>
>> def salesrecord():
>>     serial_number = 1
>>     for i in selesrecord:
>>         print first_sales_record
>>         serial_number += 1
>>         print serial_number
>>
>> salesrecord()
>>
>> 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.
>>
>> Can you let me know how can i achive this in python? As i am in learning
>> phase of python, can you let me know what would be good approach to do this
>> in python.
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>

[toc] | [next] | [standalone]


#40159

FromJohn Gordon <gordon@panix.com>
Date2013-02-28 19:23 +0000
Message-ID<kgoar7$db1$1@reader1.panix.com>
In reply to#40152
In <mailman.2663.1362078015.2939.python-list@python.org> Morten Engvoldsen <mortenengv@gmail.com> writes:

> But, if i save the serial_ number value in file, then how  will it decide
> to reset the serial number to '1' when the batch  runs on next working day.

Name the file so that it contains the date, i.e. "serial_numbers.2013-02-28".

If the file exists, you know that the program has already run today and
you can read the file to obtain the previous serial number.

If the file does not exist, you know the program has not yet run today
and you can start the serial number at 1.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#40177

FromChris Angelico <rosuav@gmail.com>
Date2013-03-01 07:52 +1100
Message-ID<mailman.2676.1362084726.2939.python-list@python.org>
In reply to#40159
On Fri, Mar 1, 2013 at 6:23 AM, John Gordon <gordon@panix.com> wrote:
> In <mailman.2663.1362078015.2939.python-list@python.org> Morten Engvoldsen <mortenengv@gmail.com> writes:
>
>> But, if i save the serial_ number value in file, then how  will it decide
>> to reset the serial number to '1' when the batch  runs on next working day.
>
> Name the file so that it contains the date, i.e. "serial_numbers.2013-02-28".
>
> If the file exists, you know that the program has already run today and
> you can read the file to obtain the previous serial number.
>
> If the file does not exist, you know the program has not yet run today
> and you can start the serial number at 1.

Probably overkill; simpler to have just one file and record the date.
Just be careful of definitions - do you use the current date UTC or
the current date local time? And be aware of what might happen if the
local clock is changed.

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web