[Tutor] The '45' bug in round()

2007-03-19 Thread Dick Moores
Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, print round(0.19945,4) 0.1994 For rounding of random samples of numbers between 0 and 1 ending in '45', the error ratio is about 0.041. Here are a few more examples: print

Re: [Tutor] Tkinter-Button class

2007-03-19 Thread Kent Johnson
ammar azif wrote: Hi, Thanks for the help guys. I have tried gui programming using Tkinter and use the Button class which accepts the command argument which is a function object. The question is how to send arguments if the function accepts arguments. A common way to do this is to

Re: [Tutor] The '45' bug in round()

2007-03-19 Thread Kent Johnson
Dick Moores wrote: Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, print round(0.19945,4) 0.1994 For rounding of random samples of numbers between 0 and 1 ending in '45', the error ratio is about 0.041. Here are a few more

Re: [Tutor] The '45' bug in round()

2007-03-19 Thread andrew clarke
On Mon, Mar 19, 2007 at 03:04:03AM -0700, Dick Moores wrote: Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, Garbage In, Garbage Out :-) Floating point numbers in Python (and other computer languages) are only an approximation:

Re: [Tutor] The '45' bug in round()

2007-03-19 Thread Dick Moores
At 03:29 AM 3/19/2007, Kent Johnson wrote: Dick Moores wrote: Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, print round(0.19945,4) 0.1994 For rounding of random samples of numbers between 0 and 1 ending in '45', the error ratio

Re: [Tutor] Tkinter-Button class

2007-03-19 Thread Kent Johnson
ammar azif wrote: Hi, Thanks for answering .. btw what do you mean by explicit , helper function? Can you explain about these functions? I just mean, define an ordinary function of no arguments that does what you want. For example, the calculator program I linked to has this Button:

Re: [Tutor] The '45' bug in round()

2007-03-19 Thread Kent Johnson
Dick Moores wrote: Kent, I did understand the points you made in that earlier thread. However, I'm unhappy with print round(0.19945,4) 0.1994 Am I the only one unhappy with this kind of rounding? IMO you are chasing a non-problem. In real-world use, you would probably not type in a

[Tutor] Making table

2007-03-19 Thread Per Jr. Greisen
Hi, I need to generate a table with different x,y,z values and write them to a file: 10.171 -15.243 -2.558 9.837 -14.511 -1.923 -23.451 -13.870 51.507 I would like to write to the files as columns 10.171 -15.243 -2.558 9.837 -14.511 -1.923 -23.451 -13.870 51.507 0.233

Re: [Tutor] Making table

2007-03-19 Thread Dave Kuhlman
On Mon, Mar 19, 2007 at 01:11:27PM +0100, Per Jr. Greisen wrote: Hi, I need to generate a table with different x,y,z values and write them to a file: 10.171 -15.243 -2.558 9.837 -14.511 -1.923 -23.451 -13.870 51.507 I would like to write to the files as columns 10.171 -15.243

Re: [Tutor] cookie expiration date format

2007-03-19 Thread Mike Hansen
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Luke Paireepinart Sent: Friday, March 16, 2007 8:31 PM To: Tim Johnson Cc: tutor@python.org Subject: Re: [Tutor] cookie expiration date format Tim Johnson wrote: Hi: I want to be able to

Re: [Tutor] Making table

2007-03-19 Thread Kent Johnson
Dave Kuhlman wrote: Try ljust and rjust. They are string functions/methods and are described here: http://docs.python.org/lib/string-methods.html Something like the following might work for you: In [1]: value = 3.45678 In [2]: (%0.3f % value).rjust(10) Out[2]: ' 3.457'

Re: [Tutor] fine in interpreter, hangs in batch

2007-03-19 Thread Switanek, Nick
Thanks very much for your help. I did indeed neglect to put the print in the code that I sent to the list. It appears that the step that is taking a long time, and that therefore makes me think that the script is somehow broken, is creating a dictionary of frequencies from the list of ngrams. To

Re: [Tutor] cookie expiration date format

2007-03-19 Thread Tim Johnson
On Monday 19 March 2007 15:33, Mike Hansen wrote: Some of the modules in the Python standard library make things a little more difficult than other languages.(Perl, Ruby, ...) This is a good example of it. Are there any 3rd party modules that let you set the expiration date to 'yesterday'?

Re: [Tutor] fine in interpreter, hangs in batch

2007-03-19 Thread Kent Johnson
Switanek, Nick wrote: Thanks very much for your help. I did indeed neglect to put the print in the code that I sent to the list. It appears that the step that is taking a long time, and that therefore makes me think that the script is somehow broken, is creating a dictionary of

Re: [Tutor] fine in interpreter, hangs in batch

2007-03-19 Thread Kent Johnson
Switanek, Nick wrote: Great, Kent, thanks. I thought that I had to check in the .keys() to see if the key was there. It seems that the method you suggest will not work if I'm looking for a value in the dictionary. If that's correct, is there a fast alternative to searching through

Re: [Tutor] The '45' bug in round()

2007-03-19 Thread Michael Hannon
On Mon, Mar 19, 2007 at 03:04:03AM -0700, Dick Moores wrote: Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, print round(0.19945,4) 0.1994 . . . Comments, Tutors? Am I way out in left field with this? I suggest you might

Re: [Tutor] Making table

2007-03-19 Thread Carroll, Barry
-Original Message- Date: Mon, 19 Mar 2007 11:53:06 -0400 From: Kent Johnson [EMAIL PROTECTED] Subject: Re: [Tutor] Making table To: tutor@python.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1; format=flowed Dave Kuhlman wrote: Try ljust and

Re: [Tutor] Making table

2007-03-19 Thread Kent Johnson
Carroll, Barry wrote: -Original Message- Date: Mon, 19 Mar 2007 11:53:06 -0400 From: Kent Johnson [EMAIL PROTECTED] Most string formatting conversions allow you to specify a width directly. For example, In [61]: value = 3.45678 In [63]: %10.3f % value Out[63]: ' 3.457' Kent

Re: [Tutor] Making table

2007-03-19 Thread Carroll, Barry
-Original Message- From: Kent Johnson [mailto:[EMAIL PROTECTED] Sent: Monday, March 19, 2007 12:59 PM To: Carroll, Barry Cc: tutor@python.org Subject: Re: [Tutor] Making table Carroll, Barry wrote: -Original Message- Date: Mon, 19 Mar 2007 11:53:06 -0400 From: Kent