Re: [Tutor] calling a module fails

2012-10-29 Thread Steven D'Aprano
On 30/10/12 12:00, richard kappler wrote: [...] If, however, I save the above in a file named hungry.py, then import hungry, I get an error, as follows: import hungry hungry(96) Traceback (most recent call last): File "", line 1, in TypeError: 'module' object is not callable So what am I mi

Re: [Tutor] calling a module fails

2012-10-29 Thread Dave Angel
On 10/29/2012 09:00 PM, richard kappler wrote: > Methinks I'm missing something obvious, but can't quite put my finger on > it. If, in the interpreter, I enter the following code: > > def hungry(batVolt): > if batVolt >94: > return ("I am not hungry at the moment") > elif 64 < ba

[Tutor] calling a module fails

2012-10-29 Thread richard kappler
Methinks I'm missing something obvious, but can't quite put my finger on it. If, in the interpreter, I enter the following code: def hungry(batVolt): if batVolt >94: return ("I am not hungry at the moment") elif 64 < batVolt < 95: return ("I'm starting to get hungry")

Re: [Tutor] greater precision?

2012-10-29 Thread Oscar Benjamin
On 29 October 2012 10:19, Dave Angel wrote: > On 10/29/2012 05:49 AM, John Collins wrote: >> >> Sorry to bother, but if I can squeeze out *at least* 15 sig figs, (30 >> or more would be better!) I'd be a happy camper! >> XNumbers addon for Excel allows over 200 sig figs by switching to base >> 256

Re: [Tutor] Help Passing Variables

2012-10-29 Thread Prasad, Ramit
David Hutto wrote: > #A little more complex in terms of params: > > def SwapCaseAndCenter(*kwargs): > > if upper_or_lower == "upper": > print a_string.center(center_num).upper() > > if upper_or_lower == "lower": > print a_string.center(center_num).lower()

Re: [Tutor] greater precision?

2012-10-29 Thread eryksun
On Mon, Oct 29, 2012 at 11:15 AM, Mark Lawrence wrote: > On 29/10/2012 12:00, Dave Angel wrote: >> >> Not silly at all. I didn't realize str(float) would truncate to 12 >> digits either. I found out by experimenting (with 2.7) in the >> interpreter. > > It's 16 digits with 3.3.0. It was changed

Re: [Tutor] greater precision?

2012-10-29 Thread Mark Lawrence
On 29/10/2012 11:39, John Collins wrote: Hi Dave, BTW, I misspoke earlier. The module name is decimal. The class name within that module is Decimal. A minor thing to me, a non programmer, but I do understand that being very precise is very important to programmers, so thank you! John. If y

Re: [Tutor] greater precision?

2012-10-29 Thread John Collins
Hi Mark, Thanks. I wouldn't know C if I fell over it. Until recently, the *only* language I'd ever used was (HP, GW)BASIC aside from Fortran 101, 3 decades ago! John. On 30/10/2012 2:45 AM, Mark Lawrence wrote: If you're more comfortable with C you can use printf style formatting see http://doc

Re: [Tutor] greater precision?

2012-10-29 Thread John Collins
Thanks Mark. I 'stuck' with 2.7.2 for these old scripts, unless I want to totally rewrite them. They are so elegant, this would realy amount to starting from scratch. I get 15 reported, and that's going to be sufficient for these 'as they are'. For more, it's a go back to year zero exercise I feel

Re: [Tutor] greater precision?

2012-10-29 Thread Mark Lawrence
On 29/10/2012 12:14, John Collins wrote: Indeed! As you saw, some outputs are, and really must be output as integers. A 1 with a decimal point followed by 15 0's would make a real mess of the face/vertex designation table. So I have to be careful where I invoke output.write("{0:.15f}".format(x))

Re: [Tutor] greater precision?

2012-10-29 Thread John Collins
Hello, Just checked my py, and 15 was the report! Wish I had known that factoid - thank you, for a very complete coverage of the broader intrinsic 'machine' + system precision - it actually makes sense to me now - it's a calculation! On 30/10/2012 2:02 AM, eryksun wrote: A double has 53 bits o

Re: [Tutor] Python Pipes

2012-10-29 Thread eryksun
On Mon, Oct 29, 2012 at 6:33 AM, Ganesh Manal wrote: > > Please give me sample python program that works with python31 Re: Python Pipes If you're looking to pipe data to, from, and between processes, look at the subprocess module: http://docs.python.org/release/3.1/library/subprocess If you wa

Re: [Tutor] greater precision?

2012-10-29 Thread Mark Lawrence
On 29/10/2012 12:00, Dave Angel wrote: Not silly at all. I didn't realize str(float) would truncate to 12 digits either. I found out by experimenting (with 2.7) in the interpreter. Note that it may differ from version to version. And that's another reason to use format. It's 16 digits wit

Re: [Tutor] greater precision?

2012-10-29 Thread eryksun
On Mon, Oct 29, 2012 at 7:05 AM, Dave Angel wrote: > > Actually, it's 64 bits. 32 bit fp wouldn't get you anywhere near 18 digits. A double has 53 bits of precisions, which is 53*log10(2) =~ 15.955 decimal digits. However, one often sees the numbers 15 and 17 quoted for the precision. It depends

Re: [Tutor] run with default value if input not given

2012-10-29 Thread Oscar Benjamin
On 29 October 2012 13:32, Oscar Benjamin wrote: > > def main(x, y='default'): > print(x) > print(y) > > if __name__ == "__main__": > main(sys.argv[1:]) A quick correction. That should be (note the *): if __name__ == "__main__": main(*sys.argv[1:]) Oscar

Re: [Tutor] run with default value if input not given

2012-10-29 Thread Oscar Benjamin
On 29 October 2012 06:06, Saad Javed wrote: > Hi, > > #!/usr/bin/env python > > import sys > > x = 'Saad is a boy' > > def main(x): > a = [] > b = x.split(' ') > for item in b: > a.append(item) > print a > if __name__ == '__main__': > x = sys.argv[1] > main(x) > > > How can I make this program run

Re: [Tutor] Python Pipes

2012-10-29 Thread Emile van Sebille
On 10/29/2012 3:33 AM, Ganesh Manal wrote: Please give me sample python program that works with python31 Start with the tutorial at http://docs.python.org/3/tutorial/index.html It'll step you through lots of sample python scripts. Emile ___ Tutor

Re: [Tutor] Python Pipes

2012-10-29 Thread brian arb
Suggestion that you restate your request in the form of a question that is less generic and more specific to what you are looking for. On Mon, Oct 29, 2012 at 6:33 AM, Ganesh Manal wrote: > Please give me sample python program that works with python31 > > > Thanks & Regards, > Ganesh Manal. > >

Re: [Tutor] greater precision?

2012-10-29 Thread John Collins
Hi Dave, Valid question. However, there are no hidden variables used in format. Each time you invoke the format method (it's a method of str), it starts from scratch using only its current arguments. i can't think of any sense in which 'default' fits here, either. Thanks, that's somewhat of a

Re: [Tutor] greater precision?

2012-10-29 Thread Dave Angel
On 10/29/2012 08:14 AM, John Collins wrote: > >> But please don't just take the format string I supplied as "right." It >> is if you always want 15 decimal digits to the right of the decimal >> point. But if you have a number like 50 thousand, then many of those >> digits to the right are invali

Re: [Tutor] Python Pipes

2012-10-29 Thread Steven D'Aprano
On 29/10/12 21:33, Ganesh Manal wrote: Please give me sample python program that works with python31 # start program print("hello world") # end program -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options

Re: [Tutor] greater precision?

2012-10-29 Thread John Collins
Hi Dave, Not silly at all. I didn't realize str(float) would truncate to 12 digits either. I found out by experimenting (with 2.7) in the interpreter. Very gracious of you to say, and generous of you to trouble yourself to experiment - thank you very much! Note that it may differ from version

Re: [Tutor] greater precision?

2012-10-29 Thread Dave Angel
On 10/29/2012 07:49 AM, John Collins wrote: > Hi Dave, >> Not true. That's just what it was truncated to upon output. If you >> want to show 15 digits, then use formatted output instead of str() >> inside the realprint() function. > BIG light bulb moment! I had no idea the str() statement was tru

Re: [Tutor] greater precision?

2012-10-29 Thread John Collins
Hi Dave, You just lost me. If you don't use any transcendental functions, then a fraction has no quantization error. It's totally precise. Ah ha! Another light bulb moment - two in one night! Thank you Dave, and all! John. ___ Tutor maillist - T

Re: [Tutor] greater precision?

2012-10-29 Thread John Collins
Hi Dave, Not true. That's just what it was truncated to upon output. If you want to show 15 digits, then use formatted output instead of str() inside the realprint() function. BIG light bulb moment! I had no idea the str() statement was truncating! I *did* search the script for "12" or "trunc"

Re: [Tutor] greater precision?

2012-10-29 Thread Dave Angel
On 10/29/2012 07:19 AM, John Collins wrote: > >> Equality. > Right, in a 1,0 sense. >> Because of rounding errors this is a dangerous operation for floating >> point >> numbers: > print 1.0 == .1 + .1 + .1 + .1 + .1 + .1 + .1 + .1 + .1 + .1 >> False > I take it that is because binary for .1 is

Re: [Tutor] greater precision?

2012-10-29 Thread John Collins
Hi Dave, Thanks, more insights! I was only concerned that there was some correction in one of the messages. And since there was only 3 minutes between them, i didn't know which might be the corrected one. They showed up here out of order. I responded to the one with the later timestamp. No, m

Re: [Tutor] greater precision?

2012-10-29 Thread Dave Angel
On 10/29/2012 06:54 AM, John Collins wrote: > Hi Steve, > Thanks. From > >>>mkpoints.py 32 32.txt > > here's a sample of the output > > -0.396087591388 -0.781284022758 0.482400140683 > -0.967387012461 -0.0838047084421 -0.239037944614 > 0.0208969821213 -0.489420208746 0.871797668848 > 0.887250003871

Re: [Tutor] greater precision?

2012-10-29 Thread John Collins
Hi Peter, Thanks. [On modern hardware] Python uses IEEE 754 double-precision internally which gives 15 to 17 digits. But of course errors may accumulate. As in my previous, this script seems to output precisely 12 significant not 15 and not 17. ???

Re: [Tutor] greater precision?

2012-10-29 Thread Dave Angel
On 10/29/2012 06:32 AM, John Collins wrote: > Hi Dave >> Did you really leave two very-similar messages 3 minutes apart? Or are >> you using a broken gateway, like Google-groups, and it hiccoughed? > Sorry, I didn't intend to - flunky LH mouse microswitch! I was only concerned that there was some

Re: [Tutor] Python Pipes

2012-10-29 Thread Mark Lawrence
On 29/10/2012 10:33, Ganesh Manal wrote: Please give me sample python program that works with python31 Thanks & Regards, Ganesh Manal. "As soon as your dream become stronger than your doubts and fears , Your dream begins to manifest . " Please give me a signed and dated cheque with the areas

Re: [Tutor] greater precision?

2012-10-29 Thread John Collins
Hi Steve, Thanks. From >>>mkpoints.py 32 32.txt here's a sample of the output -0.396087591388 -0.781284022758 0.482400140683 -0.967387012461 -0.0838047084421 -0.239037944614 0.0208969821213 -0.489420208746 0.871797668848 0.887250003871 -0.258893773768 -0.38178717178 0.426352071227 -0.45775840872

Re: [Tutor] Python Pipes

2012-10-29 Thread Peter Otten
Ganesh Manal wrote: > Please give me sample python program that works with python31 $ touch sample.py $ cat sample.py $ python3 sample.py So the minimal python3 program is an empty file. ___ Tutor maillist - Tutor@python.org To unsubscribe or change

Re: [Tutor] greater precision?

2012-10-29 Thread Peter Otten
John Collins wrote: > Hi, > OS: XP > Py: 2.7.2 > > I am running some old scripts, not written by me, that produce > substantial calculated values data as decimals, 12 significant > figures. AFAIK, the keys calls are; [On modern hardware] Python uses IEEE 754 double-precision

Re: [Tutor] run with default value if input not given

2012-10-29 Thread Brian van den Broek
On 29 Oct 2012 02:30, "Saad Javed" wrote: > > I've come up with this: > > try: > sys.argv[1] > x = sys.argv[1] > main(x) > except IndexError: > main(x) > > It works but seems hackish. > > Saad Saad, The first sys.argv is not needed. Notice how i have replied below the text i am quoting? That is

[Tutor] Python Pipes

2012-10-29 Thread Ganesh Manal
Please give me sample python program that works with python31 Thanks & Regards, Ganesh Manal. "As soon as your dream become stronger than your doubts and fears , Your dream begins to manifest . " ___ Tutor maillist - Tutor@python.org To unsubscribe o

Re: [Tutor] greater precision?

2012-10-29 Thread John Collins
Hi Dave Did you really leave two very-similar messages 3 minutes apart? Or are you using a broken gateway, like Google-groups, and it hiccoughed? Sorry, I didn't intend to - flunky LH mouse microswitch! Without knowing the type of the arguments being passed to the crosspoint() function, we ca

Re: [Tutor] greater precision?

2012-10-29 Thread Steven D'Aprano
On 29/10/12 20:46, John Collins wrote: Hi, OS: XP Py: 2.7.2 I am running some old scripts, not written by me, that produce substantial calculated values data as decimals, 12 significant figures. AFAIK, the keys calls are; "Decimal" has a specific meaning in Python different to how you appear t

Re: [Tutor] greater precision?

2012-10-29 Thread Dave Angel
On 10/29/2012 05:49 AM, John Collins wrote: Did you really leave two very-similar messages 3 minutes apart? Or are you using a broken gateway, like Google-groups, and it hiccoughed? > Hi, > OS: XP > Py: 2.7.2 > > I am running some old scripts, not written by me, that produce > substantial calcu

[Tutor] greater precision?

2012-10-29 Thread John Collins
Hi, OS: XP Py: 2.7.2 I am running some old scripts, not written by me, that produce substantial calculated values data as decimals, 12 significant figures. AFAIK, the keys calls are; from math import pi, asin, atan2, cos, sin, sqrt from math import pi, asin, atan2, cos, sin, sqrt from crosspoin

[Tutor] greater precision?

2012-10-29 Thread John Collins
Hi, OS: XP Py: 2.7.2 I am running some old scripts, not written by me, that produce substantial calculated values data as decimals, 12 significant figures. AFAIK, the keys calls are; from math import pi, asin, atan2, cos, sin, sqrt from math import pi, asin, atan2, cos, sin, sqrt from crosspoin

Re: [Tutor] help with homework

2012-10-29 Thread Asokan Pichai
On Mon, Oct 29, 2012 at 2:28 PM, Alan Gauld wrote: > On 29/10/12 08:37, Asokan Pichai wrote: > >>> teachers put stupid artificial constraints on your code, >> >> >>> >>> such as banning the use of len(). >> >> >> There may be legitim

Re: [Tutor] help with homework

2012-10-29 Thread Alan Gauld
On 29/10/12 08:37, Asokan Pichai wrote: teachers put stupid artificial constraints on your code, such as banning the use of len(). There may be legitimate learning outcomes for a teacher to specify such conditions. In that ca

Re: [Tutor] help with homework

2012-10-29 Thread Asokan Pichai
[SNIPPED] > > Always use a while loop in this situation, This is excellent advice. Use a for loop in two situations: 1. Iterating a fixed(known) number of times 2. Iterating through the contents of any container Use a while loop to iterate as long as a condition applies. > regardless of wheth

Re: [Tutor] run with default value if input not given

2012-10-29 Thread Peter Otten
Saad Javed wrote: > Hi, > > #!/usr/bin/env python > > import sys > > x = 'Saad is a boy' > > def main(x): > a = [] > b = x.split(' ') > for item in b: > a.append(item) > print a > if __name__ == '__main__': > x = sys.argv[1] > main(x) > > > How can I make this program run with the default va

Re: [Tutor] run with default value if input not given

2012-10-29 Thread Steven D'Aprano
On Mon, Oct 29, 2012 at 11:28:05AM +0500, Saad Javed wrote: > I've come up with this: > > try: > sys.argv[1] > x = sys.argv[1] > main(x) > except IndexError: > main(x) > > It works but seems hackish. There's no need to look up sys.argv[1] twice, nor any need to write main(x) in both blocks. You

Re: [Tutor] run with default value if input not given

2012-10-29 Thread Steven D'Aprano
Saad, please don't send HTML emails, as it destroys the essential formatting of your code. On Mon, Oct 29, 2012 at 11:06:14AM +0500, Saad Javed wrote: > How can I make this program run with the default value of x if I don't > specify an argument at the command line? arguments = sys.argv[1:] #