Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'definitions': 0.07; 'exist,': 0.07; '1000.': 0.09; 'confuse': 0.09; 'exists,': 0.09; 'filed': 0.09; 'option:': 0.09; 'overwrite': 0.09; 'record.': 0.09; 'runs,': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; 'file,': 0.15; "'r')": 0.16; 'email addr:python.org"': 0.16; 'f.read()': 0.16; 'increment': 0.16; 'received:74.125.82.46': 0.16; 'subject: \n ': 0.16; 'subject:entire': 0.16; 'suggestion.': 0.16; 'utc': 0.16; 'wrote:': 0.17; 'skip:{ 20': 0.17; 'subject:Issue': 0.17; 'thu,': 0.17; 'team,': 0.18; '>>>': 0.18; 'feb': 0.19; 'skip:p 30': 0.20; 'python?': 0.20; 'file.': 0.20; 'bit': 0.21; 'import': 0.21; 'not,': 0.21; 'clock': 0.22; 'simpler': 0.22; "skip:' 40": 0.22; "user's": 0.22; 'runs': 0.22; 'cc:2**0': 0.23; 'example': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '----------': 0.26; 'wrote': 0.26; 'skip:" 20': 0.26; 'am,': 0.27; 'i.e.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'chris': 0.28; 'decide': 0.28; 'run': 0.28; 'record': 0.28; 'changed.': 0.29; 'writes:': 0.29; 'date:': 0.29; 'reset': 0.29; 'probably': 0.29; "skip:' 10": 0.30; 'fri,': 0.30; 'function': 0.30; 'code': 0.31; 'file': 0.32; 'could': 0.32; 'print': 0.32; 'received:74.125.82': 0.33; 'date.': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'sequence': 0.35; 'pm,': 0.35; 'continue': 0.35; 'next': 0.35; 'subject:': 0.36; 'received:74.125': 0.36; 'compare': 0.36; 'email addr:python.org': 0.36; 'subject:with': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'does': 0.37; 'throughout': 0.37; 'previous': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'from:': 0.38; 'skip:o 20': 0.38; 'forwarded': 0.38; 'where': 0.40; 'end': 0.40; 'think': 0.40; 'your': 0.60; 'decision': 0.60; 'day,': 0.60; 'john': 0.60; 'save': 0.61; 'first': 0.61; 'time,': 0.62; 'email name:python- list': 0.62; 'provide': 0.62; 'day.': 0.63; 'maximum': 0.63; 'series': 0.63; 'times': 0.63; 'more': 0.63; 'show': 0.63; '10.': 0.64; 'here': 0.65; 'date,': 0.65; 'serial': 0.66; 'subject:day': 0.66; 'europe': 0.66; "today's": 0.66; 'today': 0.67; 'records': 0.68; 'sales': 0.70; 'day': 0.73; '11.': 0.81; '+1100': 0.84; '1:00': 0.84; '2013': 0.84; 'careful': 0.91; 'good,': 0.91; 'killed': 0.91; 'norway': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:content-transfer-encoding; bh=jY0fggZhTttM1JLvNXY/V723IcKZPT7eLZmNhsit1n4=; b=pu4c5C6rIO6RioA7Up5BR3HwRH2F6dK+5JGDZPgpfkMUhaVCAzAxT298No8rLBlZXF mwgPHHKy0YictPuvPfiuFkL+Ej5S5glVmcHsuRKt76F/gv2WG3HQ4nUrH+1PTX1Y+3QD dJF5XpTXigonaX+YY7GcxIsRvuww6GXc/EIFqmpB4Tz+qUqMJyDovQ/1t4z53ejq2w/Z E2XGaynCuISosKtGksjZfVBGNORsGylRy3UjRPXNXXKGA9ei+gJRrUL5kr/7VupFWN5D gzbf+aq5kcw1XDed7u6WXqhrTUy9AR1Lq5nMaIGR2ENHCd9Pz++sEa9UQHhDgKAD/8uK u3zQ== MIME-Version: 1.0 X-Received: by 10.180.79.227 with SMTP id m3mr339853wix.12.1362088972476; Thu, 28 Feb 2013 14:02:52 -0800 (PST) In-Reply-To: References: Date: Thu, 28 Feb 2013 23:02:52 +0100 Subject: Re: Issue with continous incrementing of unbroken sequence for a entire working day From: Morten Engvoldsen To: rosuav@gmail.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 167 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362088980 news.xs4all.nl 6957 [2001:888:2000:d::a6]:46758 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40193 Hi, I think i can use Europe time zone as current local time : import datetime as dt >>> import pytz >>> utc =3D pytz.timezone("UTC") >>> norway =3D pytz.timezone("Europe/Norway") >>> a =3D dt.datetime(2008, 7, 6, 5, 4, 3, tzinfo=3Dutc) >>> b =3D a.astimezone(norway) i think this will provide me correct current local time when clock is chang= ed... On Thu, Feb 28, 2013 at 10:44 PM, Morten Engvoldsen wrote: > Hi, > Thanks all for suggestion... > > I am using current date as current date local time. I think > datetime.datetime will provide current local date and time, so > hopefullt the function take care > if the local clock is changed... > > ---------- Forwarded message ---------- > From: Chris Angelico > To: python-list@python.org > Cc: > Date: Fri, 1 Mar 2013 07:52:04 +1100 > Subject: Re: Issue with continous incrementing of unbroken sequence > for a entire working day > On Fri, Mar 1, 2013 at 6:23 AM, John Gordon wrote: >> In Morten Engvolds= en writes: >> >>> But, if i save the serial_ number value in file, then how will it deci= de >>> 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 > > On Thu, Feb 28, 2013 at 9:41 PM, Morten Engvoldsen = wrote: >> >> Hi, >> Okey i have wrote the below program as you suggested: >> >> import time >> from datetime import date >> >> def salesrecord(): >> serial_number =3D 0 >> sales_recrod =3D {'record1':'product1', 'record2':'product2','record= 3':'product3'} >> for i in sales_recrod: >> print sales_recrod[i] >> >> serial_number +=3D 1 >> print serial_number >> fo =3D open("workfile.txt", "wb") >> fo.write(str(serial_number)) >> fo.close() >> with open("workfile.txt", 'r') as f: >> serial_number =3D f.read() >> today =3D date.today() >> >> >> >> salesrecord() >> >> >> Here i am bit confuse with where i should write the read file function t= o read the current serial number and date. also when i overwrite the file w= ith current serial number, it will overwrite the date also with current dat= e, in that case how will i compare the date. Can you please show me in my = example how can i achive this.. >> >> >> ---------- Forwarded message ---------- >> From: Matt Jones >> To: "python-list@python.org" >> Cc: >> Date: Thu, 28 Feb 2013 13:11:38 -0600 >> Subject: Re: Issue with continous incrementing of unbroken sequence for = a entire working day >> Store the day as well as the serial_number in your file. If the day is = the same as today's day, use the serial_number, if not, use 1. At the end = of you program write the current day and serial_number. >> >> Matt Jones >> >> >> On Thu, Feb 28, 2013 at 1:00 PM, Morten Engvoldsen wrote: >> Hi, >> thanks for youe suggestion. I think i will go for your second option: >> >> # Runs this loop until killed >> while True >> >> >> serial_number =3D salesrecord(serial_number) >> >> >> But, if i save the serial_ number value in file, then how will it decid= e to reset the serial number to '1' when the batch runs on next working da= y. What condition can be good, so that next day when the batch runs, it wil= l know it has to reset the value 1. Also my batch will not automatcilly ru= n whole day, this is user's decision how many times he wants to run the bat= ch in a day. Can you elebrate more how can i do that ... >> >> ---------- Forwarded message ---------- >> From: Morten Engvoldsen >> Date: Thu, Feb 28, 2013 at 5:31 PM >> Subject: Issue with continous incrementing of unbroken sequence for a en= tire working day >> To: python-list@python.org >> >> >> 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 sho= uld be set to 1 everyday when the batch runs first time in a day and the m= aximum 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 wi= ll increment as an unbroken series throughout the entire working day. The n= ext 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 =3D 1 >> for i in selesrecord: >> print first_sales_record >> serial_number +=3D 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_n= umber' 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 thi= s in python. >>