Python input function not working in 2.7 version
Hi, I am facing issue with input() of Python 2.7. When i run the program it doesn't display any line to take user input . Below is the code: def user_input() fat_grams = input("How many grams of fat are in one serving? ") total_calories = input("How many total calories are in one serving? ") print("A food product having {0} fat grams and {1} total calories",fat_grams, total_calories); return; def main(): if __name__ == "__main__": main() Also i would like to display fat_grams where {0} place holder is there and total_calories where {1} place holder is there. That is if : fat_grams = 3 total_calories = 270 Output should be: A food product having 3 fat grams and 270 total calories. But the above print function doesn't display the out put in same way. I am new to Python and i appreciate your help in advance. Look forward to hear from your team soon and have a nice day. Regards, Morten -- http://mail.python.org/mailman/listinfo/python-list
Facing issue with Python loggin logger for printing object value
Hi Team, i am new to python and i am using python loggin for log the value of the object. Below is my code : class field: field_name = "" length = 0 type = 0 value = "" def __init__(self, field_name, length, type, value): self.field_name = field_name self.length = length self.type = type self.value = value def toString(self): if self.type == 2: return self.value.zfill(self.length) else: return self.value.ljust(self.length).upper() class record: fields = [] def setValue(self, field_name, value): for element in self.fields: if field_name == element.field_name: element.value = value def toString(self): _tempStr = "" for element in self.fields: _tempStr = _tempStr + element.toString() if len(_tempStr) < 80: return _tempStr else: _lines = len(_tempStr) / 80 _i = 0 _tempStr2 = "" _newline = "" while _i < _lines: _tempStr2 = _tempStr2 + _newline + _tempStr[_i*80:(_i+1)*80] _newline = "\n" _i = _i + 1 return _tempStr2 class First_betfor00(record): def __init__(self): self.fields = [field("APPLICATION-HEADER", 40, 1, ""), field("TRANSACTION-CODE", 8, 0, "BETFOR00"), field("ENTERPRISE-NUMBER", 11, 2, ""), field("DIVISION", 11, 1, ""), field("SEQUENCE-CONTROL", 4, 2, ""), field("RESERVED-1", 6, 1, ""), field("PRODUCTION-DATE", 4, 1, "MMDD"), field("PASSWORD", 10, 1, ""), field("VERSION", 10, 1, "VERSJON002"), field("NEW-PASSWORD", 10, 1, ""), field("OPERATOR-NO", 11, 1, ""), field("SIGILL-SEAL-USE", 1, 1, ""), field("SIGILL-SEAL-DATE", 6, 1, ""), field("SIGILL-SEAL-KEY", 20, 1, ""), field("SIGILL-SEAL-HOW", 1, 1, ""), field("RESERVED-2", 143, 1, ""), field("OWN-REFERENCE-BATCH", 15, 1, ""), field("RESERVED-3", 9, 1, ""), ] class account(osv.osv_memory): _name = 'account' def create(self,cr,uid,ids,context): logger = logging.getLogger('account') hdlr = logging.FileHandler('/var/tmp/account') formatter = logging.Formatter('%(asctime)s, %(levelname)s, %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) batch = "" recordCounter = 1 dateMMDD = time.strftime('%m%d') betfor00 = Format_betfor00() betfor00.setValue("APPLICATION-HEADER", applicationHeader.toString()) betfor00.setValue("ENTERPRISE-NUMBER", enterpriseNumber) betfor00.setValue("PRODUCTION-DATE", dateMMDD) batch = betfor00.toString() line_counter = line_counter + 1 log.debug('%(batch)s') return {'type': 'state', 'state':'end'} account() In the above code i am trying to capture the value of 'batch' in the log file, but when i check log file it doesn't have any value printed. my question is is it correct way to capture the object value that is log.debug('%(batch)s') I will really appreciate the answer. Thanks in advance.. Regards, Morten -- http://mail.python.org/mailman/listinfo/python-list
issue with loggin
Hi Dave, Thanks for looking into my issue. You cannot run the program since it is in Openerp where python is used as programming language. Here python 2.7 is used. Sorry i didn't mention all the detail. My program is able to write log for other message in the log file. here 'batch' is an object and when i try to log the value of 'batch' with logger.debug('The value is %s' %batch) , it doesn't log the value. I am not sure if it is the correct if it correct formatting syntax for displaying Object value. Thanks in advance again.. I am new to Python but not in programming language.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Facing issue with Python loggin logger for printing object value
Hi Dave, Thanks for reply. I will really appreciate if you reply to my mail id and keep python list in cc, since everytime you reply my query i need to search the reply in the forwarding message of python list. Using logger.setLevel(logging.DEBUG) will log only debug message in the log file and discard other message from log file. So that's not solving the issue of my problem. I am looking into code to find out the issue. Thanks again for your effort -- http://mail.python.org/mailman/listinfo/python-list
Re: Facing issue with Python loggin logger for printing object value
Hi Dave, Thanks a lot for your reply. I have used logging.setLevel(logger.DEBUG) because of threshold as you said. I didn't copy paste the entire program since it was very huge. The "batch " which value i am trying to retrieve is in a a for loop : for payment in payment_line: but here payment_line has null value since it was not able to retrieve payment line value from the payment object. So i would like to know if payment_line has null value, will it be enter into for loop since i was able to log message which is before the for loop but the message inside the for loop i am not able to log. Thanks again... :) On Sat, Dec 29, 2012 at 5:41 PM, Dave Angel wrote: > On 12/29/2012 07:39 AM, Morten Engvoldsen wrote: > > Hi Dave, > > Thanks for reply. I will really appreciate if you reply to my mail id and > > keep python list in cc, since everytime you reply my query i need to > search > > the reply in the forwarding message of python list. > > I won't be able to remember to special-case your account, but maybe for > the next few days. Far too many others have complained when they get an > email directly, either by sending me a request message, by using an > address at the "invalid" domain, by hijacking some bogus email address, > or by having an autoreply that says "Please don't try to contact me at > this address". For a while I considered adding all such people to a > kill-file, but decided I'd miss too much. > > I suggest you get used to reading all messages, or to simply following > the thread. (For example, Thunderbird can keep all messages together > which are replies to each other) And while I've got you, it'd be nice if > you used reply-list yourself, instead of starting a new thread each time. > > > > > Using logger.setLevel(logging.DEBUG) will log only debug message in the > log > > file and discard other message from log file. So that's not solving the > > issue of my problem. I am looking into code to find out the issue. > > > > That's not what setLevel() does. It's a >= comparison, not an == one. > http://docs.python.org/2/library/logging > """Logger.setLevel(lvl) > Sets the threshold for this logger to lvl. Logging messages which are > less severe than lvl will be ignored.""" > > Perhaps you should also read the page: > http://docs.python.org/dev/howto/logging > search for the phrase " increasing order of severity" where it lists the > 5 levels, in order. The default level for the root logger is WARNING, > so it ignores DEBUG and INFO messages. I suggested changing it to > DEBUG, so those won't get ignored. > > You probably need to write a 10-line self-contained program to > experiment with this, and run it outside of openerp. Chances are > openerp is doing something special that you need to conform to. But I'm > not going to be able to guess that. > > > > -- > > DaveA > -- http://mail.python.org/mailman/listinfo/python-list
Re: Facing issue with Python loggin logger for printing object value
Hi Dev, Thanks a lot Dev for your reply. It is really a great help. Yes i have fixed what was wrong in the create method like log.debug. I have declared line_counter=1 before the for loop. i will try now to chcek the value of payment_line. Thanks again a lot. I am greateful be a member of this forum :) On Sat, Dec 29, 2012 at 6:10 PM, Dave Angel wrote: > On 12/29/2012 11:54 AM, Morten Engvoldsen wrote: > > Hi Dave, > > Thanks a lot for your reply. I have used logging.setLevel(logger.DEBUG) > > because of threshold as you said. > > > > I didn't copy paste the entire program since it was very huge. The > "batch " > > which value i am trying to retrieve is in a a for loop : > > > > for payment in payment_line: > > > > but here payment_line has null value since it was not able to retrieve > > payment line value from the payment object. > > The closest thing Python has to "null value" is called None. If > payment_line is None, then you'll get an exception on that loop. > > As I said a while ago, I have no idea how openerp handles exceptions. > Maybe it's just doing a bare except, and ignoring anything that goes > wrong in your functions. (Very bad practice) > > It could be that payment_line is an empty list. In that case, the loop > will execute zero times. That would also explain the lack of output. > > So if openerp gives you no debugging aid, then you may have to fake it > with the logger. How about logging a simple message just before the loop? > > logger.debug("value of payment_line is " + repr(payment_line)) > > Did you ever fix the other things wrong with that create method? Like > using log.debug when the object was called logger? Or incrementing > line_counter when there was no such variable, and when it would vanish > when you exited the method anyway? > > > > -- > > DaveA > -- http://mail.python.org/mailman/listinfo/python-list
Re: Facing issue with Python loggin logger for printing object value
Hi Dave, It is able to log the message with: logger.debug("value of payment_line is " +repr(payment_line)) The output is: value of payment_line is [] So it means payment_line is an empty list, so may be it could be reason it's not able to enter into the loop since the message in the for loop is not logged in the log file. Thanks and good night.. :) On Sat, Dec 29, 2012 at 7:38 PM, Morten Engvoldsen wrote: > Hi Dev, > Thanks a lot Dev for your reply. It is really a great help. Yes i have > fixed what was wrong in the create method like log.debug. I have declared > line_counter=1 before the for loop. i will try now to chcek the value of > payment_line. > > Thanks again a lot. I am greateful be a member of this forum :) > > On Sat, Dec 29, 2012 at 6:10 PM, Dave Angel wrote: > >> On 12/29/2012 11:54 AM, Morten Engvoldsen wrote: >> > Hi Dave, >> > Thanks a lot for your reply. I have used logging.setLevel(logger.DEBUG) >> > because of threshold as you said. >> > >> > I didn't copy paste the entire program since it was very huge. The >> "batch " >> > which value i am trying to retrieve is in a a for loop : >> > >> > for payment in payment_line: >> > >> > but here payment_line has null value since it was not able to retrieve >> > payment line value from the payment object. >> >> The closest thing Python has to "null value" is called None. If >> payment_line is None, then you'll get an exception on that loop. >> >> As I said a while ago, I have no idea how openerp handles exceptions. >> Maybe it's just doing a bare except, and ignoring anything that goes >> wrong in your functions. (Very bad practice) >> >> It could be that payment_line is an empty list. In that case, the loop >> will execute zero times. That would also explain the lack of output. >> >> So if openerp gives you no debugging aid, then you may have to fake it >> with the logger. How about logging a simple message just before the loop? >> >> logger.debug("value of payment_line is " + repr(payment_line)) >> >> Did you ever fix the other things wrong with that create method? Like >> using log.debug when the object was called logger? Or incrementing >> line_counter when there was no such variable, and when it would vanish >> when you exited the method anyway? >> >> >> >> -- >> >> DaveA >> > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7
Hi Cain, Thanks for your reply. I am stroning all the contents in "batchdate" and then, data = base64.encodestring(batchdata) and then writing "data" in doc file. I know i can append "***Start file***" in the batchdata, but is there a better python code like multiply * into 10 times -- any python code i can add the formatting in dynamic way instead of hardcoding with "***Start file***" line. Thanks for your reply again. On Sat, Feb 9, 2013 at 3:38 PM, D'Arcy J.M. Cain wrote: > On Sat, 9 Feb 2013 15:27:16 +0100 > Morten Engvoldsen wrote: > > I Have saved my output in .doc file and want to format the output with > > > > *Start the File > > > > Some data here > > > > > > ***End of File* > > > > Can you let me know how can i do that using Python? > > Seems pretty simple. Open the file, read it into a variable, print the > header, print the data and then print the footer. Which part are you > struggling with? Show us your code so far. > > Or is the issue with the .doc file? Is it a Word document or simple > text? > > -- > D'Arcy J.M. Cain | Democracy is three wolves > http://www.druid.net/darcy/| and a sheep voting on > +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. > IM: da...@vex.net, VOIP: sip:da...@vex.net > -- http://mail.python.org/mailman/listinfo/python-list
Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7
Hi Davea, I am using Python 2.7. -- http://mail.python.org/mailman/listinfo/python-list
Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7
Hi Dave, This sounds great, thanks for your help :) On Sat, Feb 9, 2013 at 6:13 PM, Dave Angel wrote: > On 02/09/2013 10:01 AM, Morten Engvoldsen wrote: > >> Hi Davea, >> I am using Python 2.7. >> >> > Sorry, I should have noticed the python version in the subject line, but > didn't until this reply. > > How about print >> outfile, "Start the File".center(55, "*") > after creating the file, and > > print >> outfile, "Start the File".center(55, "*") > just before closing it ? > > -- > DaveA > -- http://mail.python.org/mailman/listinfo/python-list
Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7
Hi, Thanks for your suggestion. This is a great forum for Python. :) On Sun, Feb 10, 2013 at 4:12 PM, inq1ltd wrote: > ** > > On Saturday, February 09, 2013 03:27:16 PM Morten Engvoldsen wrote: > > > Hi Team, > > > I Have saved my output in .doc file and want to format the output with > > > > > > *Start the File > > > > > > Some data here > > > > > > > > > ***End of File* > > > > > > Can you let me know how can i do that using Python? > > > > > > Look up the textwrap module > > > > import the textwrap module. > > > > from the textwrap module you can > > import dedent, wrap, and fill > > > > These are great for formatting text. > > > > jd > > inqvista.com > > > > > > > > > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7
Hi Dave, This is good code, simple but makes the Coding Standard better.. Thanks to all again On Sun, Feb 10, 2013 at 5:01 PM, David Hutto wrote: > Kind of like below: > > david@david-HP-Compaq-dc7600-Convertible-Minitower:~$ python > Python 2.7.3 (default, Aug 1 2012, 05:16:07) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> f = open("/home/david/file_doc.doc",'a') > >>> text = "data here" > >>> f.write("***Start File***\n%s\n***End File***\n" % text) > >>> f.close() > >>> > -- http://mail.python.org/mailman/listinfo/python-list
Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7
Hi Dave, Thanks again for suggestion On Sun, Feb 10, 2013 at 5:30 PM, David Hutto wrote: > I haven't looked at text wrapper, but it would probably look > something like this in a function, untested: > > def text_wrapper(file_name = None, pre_text = None, text = None, > post_text = None): > f = open(file, 'a') > f.write("%s\n%s\n%s\n" % (pre_text = None, text, post_text = None) > f.close() > > > -- > Best Regards, > David Hutto > CEO: http://www.hitwebdevelopment.com > -- http://mail.python.org/mailman/listinfo/python-list
Re: Any idea how i can format my output file with ********************Start file*********************** usinf Python 2.7
Hi Dave, Thanks for your reply with full function :) Great forum.. :) On Sun, Feb 10, 2013 at 5:46 PM, David Hutto wrote: > Here is the full function with an instance using the function: > > def text_wrapper(file_name = None, pre_text = None, text = None, > post_text = None): > f = open(file_name, 'a') > f.write("%s\n%s\n%s\n" % (pre_text, text, post_text)) > f.close() > > > text_wrapper(file_name = r"/home/david/file_doc.doc", pre_text = > "***Start File***", text = "Some data here.", post_text = "***End > File***") > -- http://mail.python.org/mailman/listinfo/python-list
Verification of bank number using modulus 11
Hi Team, I am trying to verify the account number using the following algorithm: "The valid account number is 11 numeric digit without seperator. Eg. 8607947 is a valid account number. All banks apply a modulus-based method for the validation of the account structure. The 10-digit account number is multiplied from left to right by the following weights: 5, 4, 3, 2, 7, 6, 5, 4, 3, 2. The resulting numbers are added up and divided by 11. The remainder is subtracted from 11 and becomes the check digit. If the remainder is 0, the check digit will be 0. If digits 5 and 6 of the account number are zeros, the check digit is calculated on the 7, 8, 9 and 10th digit of the account number. Account numbers for which the remainder is 1 (check digit 10) cannot be used." I am trying to validate the Norway account number using the algorithm mentioned in the following document: http://www.cnb.cz/miranda2/export/sites/www.cnb.cz/cs/platebni_styk/iban/download/TR201.pdf Here is my code: def calc_checkdigit(isbn): isbn = isbn.replace(".", "") check_digit = int(isbn[-1]) isbn = isbn[:-1] if len(isbn) != 10: return False result = sum((10 - i) * (int(x) if x != 'X' else 10) for i, x in enumerate(isbn)) return (result % 11) == check_digit calc_checkdigit(""8601.11.17947"") In my program : it is calculating 10 digit with weights 10-1, but according to above algorithm the weights should be : 5, 4, 3, 2, 7, 6, 5, 4, 3, 2. Could you please let me know how can i calculate the 10 digit with weights 5, 4, 3, 2, 7, 6, 5, 4, 3, 2. I am using python 2.7. Thanks in advance team for help.. ): -- http://mail.python.org/mailman/listinfo/python-list
Re: Verification of bank number using modulus 11
Hi Team, Thanks for the code. I have altered the code with below code, it is able to validate the number now, def calc_checkdigit(isbn): isbn = isbn.replace(".", "") check_digit = int(isbn[-1]) isbn = isbn[:-1] if len(isbn) != 10: return False weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2] result = sum(w * (int(x)) for w, x in zip(weights, isbn)) remainder = result % 11 if remainder == 0: check = 0 else: check = 11 - remainder return check == check_digit calc_checkdigit(""8601.11.**17947"") But can you tell me how could i implement below "If digits 5 and 6 of the account number are zeros, the check digit is calculated on the 7, 8, 9 and 10th digit of the account number." which means if account number is "8601.00.**17947" then check digit is calculate as result = (1*5) + (7*4)+ (9*3)+(4*2) remainder = result % 11 check_digit = 11 - remainder Can you tell me how can i implement this ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Verification of bank number using modulus 11
Hi, Thanks for below code: After this code: isbn = isbn[:-1] if len(isbn) != 10: return False Add: if isbn[4:6] == "00": isbn = isbn[6:] It is working exactly how it should :) I didn't even change that part . The zip function automatically truncates to the length of the shorter input sequence. Thanks a lot again :) Have a nice day.. On Tue, Feb 19, 2013 at 11:59 PM, Morten Engvoldsen wrote: > Hi Team, > Thanks for the code. > I have altered the code with below code, it is able to validate the > number now, > > def calc_checkdigit(isbn): > isbn = isbn.replace(".", "") > check_digit = int(isbn[-1]) > isbn = isbn[:-1] > if len(isbn) != 10: > return False > weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2] > result = sum(w * (int(x)) for w, x in zip(weights, isbn)) > remainder = result % 11 > if remainder == 0: >check = 0 > else: >check = 11 - remainder > return check == check_digit > > calc_checkdigit(""8601.11.**17947"") > > > But can you tell me how could i implement below > > "If digits 5 and 6 of the account number are zeros, the check digit is > calculated on the 7, 8, 9 and 10th digit of the account number." > > which means if account number is "8601.00.**17947" then check digit is > calculate as > > result = (1*5) + (7*4)+ (9*3)+(4*2) > > remainder = result % 11 > > check_digit = 11 - remainder > > Can you tell me how can i implement this ? > > > > > > > -- http://mail.python.org/mailman/listinfo/python-list
Number validation issue
Hi , I have wrote the below code to validate a number using modulus 10 and 11: def is_valid_number(checknum, mod): if mod == 10: if not len(checknum) >= 2 and len(checknum) <=25: return False number = tuple(int(i) for i in reversed(str(checknum)) ) return (sum(int(num) * 2 for num in number[1::2]) % 10) == 0 elif mod == 11: if not len(checknum)!= 11: return False weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11) == 0 is_valid_number("12345678217", 10) The above code is able to validate 25 length number for modulus 10 , but for modulus 11 i have done the validation only for 11 digit, Since for modulus 11 the weight should be in .4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 in this format. Could you please let me know how can i validate the 25 length number for modulus 11 with weight ...4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 in this format. Regards, Morten -- http://mail.python.org/mailman/listinfo/python-list
Re: Number validation issue
Hi, Thanks for your reply. Here in your code i think you didn't multiply the given number with the weight i have mentioned. The each digit of the given number should multiply with weight ...4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, 1 in this format. That is in detail: To verify the number use the following weights from right to left: 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7... Multiply each digit by its corresponding weight. Add the results together. For the number to be correct the total must be divisible by 11. Field with control digit 1 2 3 4 5 6 7 8 5 Weight 3 2 7 6 5 4 3 2 1 Produce +3 +4 +21 +24 +25 +24 +21 +16 +5 =143 The sum must be divisible by 11 (143 divided by 11 leaves a remainder of 0). So my code has validated only the length of 11 digit. So i am looking for 'n' length of number should be validated with weight ...4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, 1 from left to right.. Thanks again ... On Fri, Feb 22, 2013 at 4:33 PM, Alec Taylor wrote: > Whoops, my mistake: > > In [5]: [not len(x) >= 2 and len(x)<=25 for x in [str(y) for y in > xrange(30)]] > Out [5]: [True]*10, [False]*20 > > But still, I'm guessing that's not the result you were looking for… > > On Sat, Feb 23, 2013 at 2:30 AM, Alec Taylor > wrote: > > Out[1]: '0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 > > 24 25 26 27 28 29' > > > > In [2]: [not len(x) >= 2 and len(x)<=25 for x in _] > > Out[2]: [True]*79 # shorthand to prevent spam > > > > > > I trust you can see the error now! > > > > On Sat, Feb 23, 2013 at 2:09 AM, Morten Engvoldsen > wrote: > >> Hi , > >> I have wrote the below code to validate a number using modulus 10 and > 11: > >> > >> def is_valid_number(checknum, mod): > >> if mod == 10: > >> if not len(checknum) >= 2 and len(checknum) <=25: > >> return False > >> number = tuple(int(i) for i in reversed(str(checknum)) ) > >> return (sum(int(num) * 2 for num in number[1::2]) % 10) == 0 > >> elif mod == 11: > >> if not len(checknum)!= 11: > >> return False > >> weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] > >> return (sum(w * int(x) for w, x in zip(weights, checknum)) % > 11) == > >> 0 > >> > >> is_valid_number("12345678217", 10) > >> > >> The above code is able to validate 25 length number for modulus 10 , > but for > >> modulus 11 i have done the validation only for 11 digit, Since for > modulus > >> 11 the weight should be in > >> .4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 in this format. > >> > >> Could you please let me know how can i validate the 25 length number for > >> modulus 11 with weight ...4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, > 4, 3, > >> 2, 1 in this format. > >> > >> Regards, > >> Morten > >> > >> > >> > >> -- > >> http://mail.python.org/mailman/listinfo/python-list > >> > -- http://mail.python.org/mailman/listinfo/python-list
Re: Number validation issue
Hi, Just to clear the confusion: i am talking about below part of my code: elif mod == 11: >> if not len(checknum)!= 11: >> return False >> weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] >> return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11) ==0 for which i am looking for solution that it should validate the 'n' length of number with weight ...4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, 1 in this format from left to right. Thanks in advance again.. On Fri, Feb 22, 2013 at 5:32 PM, Morten Engvoldsen wrote: > Hi, > Thanks for your reply. > > Here in your code i think you didn't multiply the given number with the > weight i have mentioned. The each digit of the given number should > multiply with weight ...4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, > 1 in this format. That is in detail: > > To verify the number use the following weights from right to left: > 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7... > Multiply each digit by its corresponding weight. Add the results together. > For the number to be correct the > total must be divisible by 11. > Field with control digit 1 2 3 4 5 6 7 8 5 > Weight 3 2 7 6 5 4 3 2 1 > Produce +3 +4 +21 +24 +25 +24 +21 +16 +5 =143 > The sum must be divisible by 11 (143 divided by 11 leaves a remainder of > 0). > > So my code has validated only the length of 11 digit. So i am looking for > 'n' length of number should be validated with weight > ...4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, 1 from left to > right.. > > Thanks again ... > > > > On Fri, Feb 22, 2013 at 4:33 PM, Alec Taylor wrote: > >> Whoops, my mistake: >> >> In [5]: [not len(x) >= 2 and len(x)<=25 for x in [str(y) for y in >> xrange(30)]] >> Out [5]: [True]*10, [False]*20 >> >> But still, I'm guessing that's not the result you were looking for… >> >> On Sat, Feb 23, 2013 at 2:30 AM, Alec Taylor >> wrote: >> > Out[1]: '0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 >> > 24 25 26 27 28 29' >> > >> > In [2]: [not len(x) >= 2 and len(x)<=25 for x in _] >> > Out[2]: [True]*79 # shorthand to prevent spam >> > >> > >> > I trust you can see the error now! >> > >> > On Sat, Feb 23, 2013 at 2:09 AM, Morten Engvoldsen < >> mortene...@gmail.com> wrote: >> >> Hi , >> >> I have wrote the below code to validate a number using modulus 10 and >> 11: >> >> >> >> def is_valid_number(checknum, mod): >> >> if mod == 10: >> >> if not len(checknum) >= 2 and len(checknum) <=25: >> >> return False >> >> number = tuple(int(i) for i in reversed(str(checknum)) ) >> >> return (sum(int(num) * 2 for num in number[1::2]) % 10) == 0 >> >> elif mod == 11: >> >> if not len(checknum)!= 11: >> >> return False >> >> weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] >> >> return (sum(w * int(x) for w, x in zip(weights, checknum)) % >> 11) == >> >> 0 >> >> >> >> is_valid_number("12345678217", 10) >> >> >> >> The above code is able to validate 25 length number for modulus 10 , >> but for >> >> modulus 11 i have done the validation only for 11 digit, Since for >> modulus >> >> 11 the weight should be in >> >> .4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 in this >> format. >> >> >> >> Could you please let me know how can i validate the 25 length number >> for >> >> modulus 11 with weight ...4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, >> 4, 3, >> >> 2, 1 in this format. >> >> >> >> Regards, >> >> Morten >> >> >> >> >> >> >> >> -- >> >> http://mail.python.org/mailman/listinfo/python-list >> >> >> > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Number validation issue
Hi, My below code is wrong : elif mod == 11: >> if not len(checknum)!= 11: >> return False >> weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] >> return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11) ==0 it works for 9 digit number , not 11 digit number, so i have changed the code and sending again with correct code with valid number: def is_valid_number(checknum): weights = [3, 2, 7, 6, 5, 4, 3, 2, 1] return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11) == 0 is_valid_number("123456785") This code validate this 9 digit number "123456785" with below algorithm: To verify the number use the following weights from right to left: 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7... Multiply each digit by its corresponding weight. Add the results together. For the number to be correct the total must be divisible by 11. Field with control digit 1 2 3 4 5 6 7 8 5 Weight 3 2 7 6 5 4 3 2 1 Produce +3 +4 +21 +24 +25 +24 +21 +16 +5 =143 The sum must be divisible by 11 (143 divided by 11 leaves a remainder of 0). So i am looking for solution how i can change this code to validate with weight 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7... from right to left for any length of number. This code validate only 9 digit number. Sorry for inconvience :( -- http://mail.python.org/mailman/listinfo/python-list
Re: Number validation issue
Hi, Just to make it more clear: I am looking for how to generate the weight in : 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7.. format for any length of number instead of weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] only for fixed digit. My below code can check only for 9 digit, so if we provide a number of more than 9 digit, it is not able to check that number. Hope, this makes clear what i am looking for... On Fri, Feb 22, 2013 at 6:27 PM, Morten Engvoldsen wrote: > Hi, > My below code is wrong : > > > elif mod == 11: > >> if not len(checknum)!= 11: > >> return False > >> weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] > >> return (sum(w * int(x) for w, x in zip(weights, checknum)) % > 11) ==0 > > it works for 9 digit number , not 11 digit number, so i have changed the > code and sending again with correct code with valid number: > > def is_valid_number(checknum): > weights = [3, 2, 7, 6, 5, 4, 3, 2, 1] > > return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11) == 0 > > is_valid_number("123456785") > > This code validate this 9 digit number "123456785" with below algorithm: > > > To verify the number use the following weights from right to left: > 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7... > Multiply each digit by its corresponding weight. Add the results together. > For the number to be correct the > total must be divisible by 11. > Field with control digit 1 2 3 4 5 6 7 8 5 > Weight 3 2 7 6 5 4 3 2 1 > Produce +3 +4 +21 +24 +25 +24 +21 +16 +5 =143 > The sum must be divisible by 11 (143 divided by 11 leaves a remainder of > 0). > > So i am looking for solution how i can change this code to validate with > weight 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7... from > right to left for any length of number. This code validate only 9 digit > number. > > Sorry for inconvience :( > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Number validation issue
> > Hi, > Yes true, i need to generate weight at run time rather than hard coding it, following are some solution: Since the max length of thenumber should be 25 and minimum should be 2 so code will be in this way: def is_valid_isbn13(isbn13): if not len(checknum) >= 2 and len(checknum) <=25: return False weigth = '1' + ''.join(map(str,range(2,8))*4) ex_weigth = list(reversed(list(weigth)[: int(len(isbn13))])) return (sum(int(w) * int(x) for w, x in zip(list(ex_weigth), list(isbn13))) % 11 == 0) is_valid_isbn13("123456785") This code works fine for any length of digit between 2 to 25, this is what exactly i need, is there any other better approch you have to generate the weight at run time. > > -- Forwarded message -- > From: Dave Angel > To: python-list@python.org > Cc: > Date: Fri, 22 Feb 2013 13:45:30 -0500 > Subject: Re: Number validation issue > On 02/22/2013 01:27 PM, Morten Engvoldsen wrote: > >> Hi, >> Just to make it more clear: I am looking for how to generate the weight >> in : >> 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7.. format for any >> length of number instead of >> >> weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] >> >> only for fixed digit. >> >> My below code can check only for 9 digit, so if we provide a number of >> more >> than 9 digit, it is not able to check that number. Hope, this makes clear >> what i am looking for... >> >> You keep top-posting, so we keep losing the context. > > zip() stops at the shorter of the two iterables. And itertools.cycle() > will repeat a list infinitely. The two of them should be able to solve your > problem. > > > -- > DaveA > > > > ------ Forwarded message -- > From: Ian Kelly > To: Python > Cc: > Date: Fri, 22 Feb 2013 11:50:13 -0700 > Subject: Re: Number validation issue > On Fri, Feb 22, 2013 at 11:27 AM, Morten Engvoldsen > wrote: > > Hi, > > Just to make it more clear: I am looking for how to generate the weight > in : > > 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7.. format for any > > length of number instead of > > > > weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] > > > > only for fixed digit. > > > > My below code can check only for 9 digit, so if we provide a number of > more > > than 9 digit, it is not able to check that number. Hope, this makes clear > > what i am looking for... > > It sounds like you probably should generate the list of weights at > run-time rather than hard-coding it as a literal. Have you tried > this? > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 113, Issue 192
Hi, Okey i will change the function name :) Do you have any suggestion to generate the weight at run time rather than hard coding it... > > -- Forwarded message -- > From: Dennis Lee Bieber > To: python-list@python.org > Cc: > Date: Sat, 23 Feb 2013 14:03:23 -0500 > Subject: Re: Number validation issue > On Sat, 23 Feb 2013 10:11:04 +0100, Morten Engvoldsen > declaimed the following in > gmane.comp.python.general: > > > > > > > Hi, > > > > > Yes true, i need to generate weight at run time rather than hard coding > it, > > following are some solution: > > > > Since the max length of thenumber should be 25 and minimum should be 2 so > > code will be in this way: > > > > def is_valid_isbn13(isbn13): > > Isn't an ISBN13 -- by definition -- 13 digits (ignoring hyphens). > > If your goal is to compute a checksum for a non-fixed length of > data, I'd suggest changing the name of the function. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ > > -- http://mail.python.org/mailman/listinfo/python-list
Issue with continous incrementing of unbroken sequence for a entire working day
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
Re: Issue with continous incrementing of unbroken sequence for a entire working day
Hi, thanks for youe suggestion. I think i will go for your second option: # Runs this loop until killed while True 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. 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 > 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 > 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 >> >> > -- http://mail.python.org/mailman/listinfo/python-list
Fwd: Issue with continous incrementing of unbroken sequence for a entire working day
Hi, Okey i have wrote the below program as you suggested: import time from datetime import date def salesrecord(): serial_number = 0 sales_recrod = {'record1':'product1', 'record2':'product2','record3':'product3'} for i in sales_recrod: print sales_recrod[i] serial_number += 1 print serial_number fo = open("workfile.txt", "wb") fo.write(str(serial_number)) fo.close() with open("workfile.txt", 'r') as f: serial_number = f.read() today = date.today() salesrecord() Here i am bit confuse with where i should write the read file function to read the current serial number and date. also when i overwrite the file with current serial number, it will overwrite the date also with current date, 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 = 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 ... -- Forwarded message -- From: Morten Engvoldsen Date: Thu, Feb 28, 2013 at 5:31 PM Subject: Issue with continous incrementing of unbroken sequence for a entire 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 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
Re: Issue with continous incrementing of unbroken sequence for a entire working day
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 Engvoldsen > 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 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 = 0 > sales_recrod = {'record1':'product1', > 'record2':'product2','record3':'product3'} > for i in sales_recrod: > print sales_recrod[i] > > serial_number += 1 > print serial_number > fo = open("workfile.txt", "wb") > fo.write(str(serial_number)) > fo.close() > with open("workfile.txt", 'r') as f: > serial_number = f.read() > today = date.today() > > > > salesrecord() > > > Here i am bit confuse with where i should write the read file function to > read the current serial number and date. also when i overwrite the file with > current serial number, it will overwrite the date also with current date, 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 > 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 ... > > -- Forwarded message -- > From: Morten Engvoldsen > Date: Thu, Feb 28, 2013 at 5:31 PM > Subject: Issue with continous incrementing of unbroken sequence for a entire > 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 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_
Re: Issue with continous incrementing of unbroken sequence for a entire working day
Hi, I think i can use Europe time zone as current local time : import datetime as dt >>> import pytz >>> utc = pytz.timezone("UTC") >>> norway = pytz.timezone("Europe/Norway") >>> a = dt.datetime(2008, 7, 6, 5, 4, 3, tzinfo=utc) >>> b = a.astimezone(norway) i think this will provide me correct current local time when clock is changed... 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 Engvoldsen >> 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 > > 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 = 0 >> sales_recrod = {'record1':'product1', >> 'record2':'product2','record3':'product3'} >> for i in sales_recrod: >> print sales_recrod[i] >> >> serial_number += 1 >> print serial_number >> fo = open("workfile.txt", "wb") >> fo.write(str(serial_number)) >> fo.close() >> with open("workfile.txt", 'r') as f: >> serial_number = f.read() >> today = date.today() >> >> >> >> salesrecord() >> >> >> Here i am bit confuse with where i should write the read file function to >> read the current serial number and date. also when i overwrite the file with >> current serial number, it will overwrite the date also with current date, 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 >> > 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 ... >> >> -- Forwarded message -- >> From: Morten Engvoldsen >> Date: Thu, Feb 28, 2013 at 5:31 PM >> Subject: Issue with continous incrementing of unbroken sequence for a entire >> working day >&g
Re: Issue with continous incrementing of unbroken sequence for a entire working day
Hi, Thanks.. :) so simply i can use time.strftime("%d%-m-%y %H:%M") , and then i can compare the date -- Forwarded message -- From: Chris Angelico To: python-list@python.org Cc: Date: Fri, 1 Mar 2013 18:59:16 +1100 Subject: Re: Issue with continous incrementing of unbroken sequence for a entire working day On Fri, Mar 1, 2013 at 6:50 PM, Morten Engvoldsen wrote: > Hi, > No i don't want user to blame when date is changed and serial number > reset when it should not. Do you think the following function will > help for this: > > import datetime as dt >>>> import pytz >>>> utc = pytz.timezone("UTC") >>>> norway = pytz.timezone("Europe/Norway") >>>> a = dt.datetime(2008, 7, 6, 5, 4, 3, tzinfo=utc) >>>> b = a.astimezone(norway) > > Your suggestion is really appreciated.. (posting reply on-list, hope that's okay!) That would be fine for the normal case. It's just possible that the user will change the computer's clock, which would result in the serial changing oddly. If that's not a problem to you, the job's done! ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Issue with continous incrementing of unbroken sequence for a entire working day
Hi, I have wrote the below code for getting the serial number: look like i am able to get correct serial number: from datetime import date def read_data_file(): with open("workfile.txt", 'r') as f: for line in f.readlines(): read_data = line.split(' ') return read_data def write_data_file(data): fo = open("workfile.txt", "w") fo.write(str(data)) fo.close() def comput_date(read_date, now_time, read_serial): if read_date == now_time: read_serial = int(read_serial) return read_serial + 1 else: read_serial = 1 return read_serial def process_sales_record(): now_time = time.strftime("%d-%m-%y") readdata = read_data_file() if readdata: read_serial = readdata[0] read_date = readdata[1] copute_date = comput_date(read_date, now_time, read_serial) serial_number = copute_date print serial_number sales_recrod = {'record1':'product1', 'record2':'product2','record3':'product3'} for i in sales_recrod: print sales_recrod[i] serial_number += 1 print serial_number data = str(serial_number) + ' ' + now_time writedata = write_data_file(data) print readdata Kindly suggest how can i improve this code now or is it okey in this way.. On Fri, Mar 1, 2013 at 10:42 AM, Morten Engvoldsen wrote: > Hi, > Thanks.. :) > so simply i can use time.strftime("%d%-m-%y %H:%M") , and then i can > compare the date > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Issue with continous incrementing of unbroken sequence for a entire working day
Hi, Yes, i think checking only date is sufficient . here is my code: from datetime import date def read_data_file(): with open("workfile.txt", 'r') as f: for line in f.readlines(): read_data = line.split(' ') return read_data def write_data_file(data): fo = open("workfile.txt", "w") fo.write(str(data)) fo.close() def comput_date(read_date, now_time, read_serial): if read_date == now_time: read_serial = int(read_serial) return read_serial + 1 else: read_serial = 1 return read_serial def process_sales_record(): now_time = time.strftime("%d-%m-%y") readdata = read_data_file() if readdata: read_serial = readdata[0] read_date = readdata[1] copute_date = comput_date(read_date, now_time, read_serial) serial_number = copute_date print serial_number sales_recrod = {'record1':'product1', 'record2':'product2','record3':'product3'} for i in sales_recrod: print sales_recrod[i] serial_number += 1 print serial_number data = str(serial_number) + ' ' + now_time writedata = write_data_file(data) print readdata Can you give me suggestion how can i improve this code -- Forwarded message -- From: MRAB To: python-list@python.org Cc: Date: Fri, 01 Mar 2013 14:09:43 + Subject: Re: Issue with continous incrementing of unbroken sequence for a entire working day On 2013-03-01 09:42, Morten Engvoldsen wrote: Hi, Thanks.. :) so simply i can use time.strftime("%d%-m-%y %H:%M") , and then i can compare the date I think you're only interested in the date, not the time of day: time.strftime("%d-%m-%y") -- http://mail.python.org/mailman/listinfo/python-list
Re: Issue with continous incrementing of unbroken sequence for a entire working day
Hi, Thanks to all.. this is great forum with so many good people. I have learnt a lot of Python from this forum. Hope one day i will learn enough that i can start answering in this forum.. :) Thanks again.. -- http://mail.python.org/mailman/listinfo/python-list