Re: [Tutor] Built In Functions

2013-12-17 Thread Mark Lawrence
On 17/12/2013 23:04, Dave Angel wrote: On Wed, 18 Dec 2013 09:32:03 +1100, Steven D'Aprano wrote: > if all (x> 0 for x in (a, b, c): Oops, yes, thanks for the correction. Er, I mean, yes, you have found my deliberate mistake and passed the test! But I didn't catch the other missing bi

Re: [Tutor] Getting Started

2013-12-17 Thread Alan Gauld
On 17/12/13 19:47, Chris Acreman wrote: I have programming experience using Fortran, Pascal, Modula 2, and some training in C++. My nephew told me about Python and it sounded intriguing. I downloaded Python 3.3.0 from this website (www.python.org ) and installed it with no

Re: [Tutor] Getting Started

2013-12-17 Thread Amit Saha
Hello Chris, On Wed, Dec 18, 2013 at 5:47 AM, Chris Acreman wrote: > I have programming experience using Fortran, Pascal, Modula 2, and some > training in C++. My nephew told me about Python and it sounded intriguing. > I downloaded Python 3.3.0 from this website (www.python.org) and installed >

[Tutor] Getting Started

2013-12-17 Thread Chris Acreman
I have programming experience using Fortran, Pascal, Modula 2, and some training in C++. My nephew told me about Python and it sounded intriguing. I downloaded Python 3.3.0 from this website (www.python.org) and installed it with no apparent difficulty. To learn the language I bought a book fr

Re: [Tutor] Built In Functions

2013-12-17 Thread Dave Angel
On Wed, 18 Dec 2013 09:32:03 +1100, Steven D'Aprano wrote: > if all (x> 0 for x in (a, b, c): Oops, yes, thanks for the correction. Er, I mean, yes, you have found my deliberate mistake and passed the test! But I didn't catch the other missing bit, a right parenthesis, now did I? --

Re: [Tutor] set locals

2013-12-17 Thread Steven D'Aprano
On Tue, Dec 17, 2013 at 04:52:25PM +0100, spir wrote: > Hello, > > is it at all possible to set new vars (or any symbol) into an existing > scope (typically locals())? In general, no. The only time that writing to locals() is guaranteed to work is when you are in the top-level scope and locals

Re: [Tutor] Built In Functions

2013-12-17 Thread Steven D'Aprano
On Tue, Dec 17, 2013 at 05:30:00PM -0500, Dave Angel wrote: > On Wed, 18 Dec 2013 02:39:43 +1100, Steven D'Aprano > wrote: > >if a > 0 and b > 0 and c > 0: > >if all(x for x in (a, b, c): > > Er, perhaps it should be: > > if all (x> 0 for x in (a, b, c): Oops, yes, thanks for the corre

Re: [Tutor] Built In Functions

2013-12-17 Thread Dave Angel
On Wed, 18 Dec 2013 02:39:43 +1100, Steven D'Aprano wrote: if a > 0 and b > 0 and c > 0: if all(x for x in (a, b, c): Er, perhaps it should be: if all (x> 0 for x in (a, b, c): -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscrib

Re: [Tutor] arrangement of datafile

2013-12-17 Thread Peter Otten
Amrita Kumari wrote: > Hi, > > I am new in programming and want to try Python programming (which is > simple and easy to learn) to solve one problem: in which > I have various long file like this: > > 1 GLY HA2=3.7850 HA3=3.9130 > 2 SER H=8.8500 HA=4.3370 N=115.7570 > 3 LYS H=8.7530 HA=4.0340 HB

[Tutor] arrangement of datafile

2013-12-17 Thread Amrita Kumari
Hi, I am new in programming and want to try Python programming (which is simple and easy to learn) to solve one problem: in which I have various long file like this: 1 GLY HA2=3.7850 HA3=3.9130 2 SER H=8.8500 HA=4.3370 N=115.7570 3 LYS H=8.7530 HA=4.0340 HB2=1.8080 N=123.2380 4 LYS H=7.9100 HA=3.

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
>>> Look at this line: >>> >>> > if __name__ == " __main__": >>> >> >> do so very closely :) > > In monospaced font :) > > Took me forever to see it, thanks Gmail... Ok ... found it ;-) Thanks! ___ Tutor maillist - Tutor@python.org To unsubscribe or ch

Re: [Tutor] Built In Functions

2013-12-17 Thread Zachary Ware
On Tue, Dec 17, 2013 at 10:37 AM, Wolfgang Maier wrote: > Peter Otten <__peter__ web.de> writes: > >> Look at this line: >> >> > if __name__ == " __main__": >> > > do so very closely :) In monospaced font :) Took me forever to see it, thanks Gmail... -- Zach __

Re: [Tutor] Built In Functions

2013-12-17 Thread Wolfgang Maier
Peter Otten <__peter__ web.de> writes: > Look at this line: > > > if __name__ == " __main__": > do so very closely :) Wolfgang ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/li

Re: [Tutor] Built In Functions

2013-12-17 Thread Peter Otten
Rafael Knuth wrote: > I just wrote a unittest for this function here: > > def PositiveCalculator(*summands): > if all(x > 0 for x in summands): > return sum(summands) > else: > raise ValueError("negative value") > > Here's the test (I want to test whether the function wor

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
I just wrote a unittest for this function here: def PositiveCalculator(*summands): if all(x > 0 for x in summands): return sum(summands) else: raise ValueError("negative value") Here's the test (I want to test whether the function works if the user enters floats instead of

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
>> def check_values(a, b): >> if all(number >= 0 for number in range(a, b)): >> return True >> else: >> raise ValueError("negative number") >> >> And: >> def PositiveCalculator(a, b): >> if a > 0 and b > 0: >> return a + b >> else: >> raise Va

[Tutor] set locals

2013-12-17 Thread spir
Hello, is it at all possible to set new vars (or any symbol) into an existing scope (typically locals())? scope[name] = value raises by me an error like: TypeError: 'mappingproxy' object does not support item assignment I guess 'mappingproxy' is the implementation name of a scope (her

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
> BUT: this really doesn't make much sense! Your if construct is a lot more > readable than what any or all would give you in this example. > As pointed out repeatedly here, you can always replace any() and all() with > a combination of for and if, it's really a question of readability (and > style

Re: [Tutor] Built In Functions

2013-12-17 Thread Mark Lawrence
On 17/12/2013 14:21, Rafael Knuth wrote: Hej there, I use any() and all() frequently. For example, suppose you have a function that takes a list of numbers, and they are all supposed to be positive. def calculate_values(numbers): if all(number > 0 for number in numbers): # do the

Re: [Tutor] Built In Functions

2013-12-17 Thread Wolfgang Maier
Rafael Knuth gmail.com> writes: > > Hej there, > > > I use any() and all() frequently. For example, suppose you have a > > function that takes a list of numbers, and they are all supposed to be > > positive. > > > > def calculate_values(numbers): > > if all(number > 0 for number in numbers)

Re: [Tutor] Built In Functions

2013-12-17 Thread Steven D'Aprano
On Tue, Dec 17, 2013 at 03:21:34PM +0100, Rafael Knuth wrote: > def PositiveCalculator(a, b): > if a > 0 and b > 0: > return a + b > else: > raise ValueError("negative number") > > In this function one negative number is tolerated: > > def PositiveCalculator(a, b): >

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
got it! Thanks, Peter On Tue, Dec 17, 2013 at 4:27 PM, Peter Otten <__pete...@web.de> wrote: > Rafael Knuth wrote: > >> Hej there, >> >>> I use any() and all() frequently. For example, suppose you have a >>> function that takes a list of numbers, and they are all supposed to be >>> positive. >>> >

Re: [Tutor] Built In Functions

2013-12-17 Thread Peter Otten
Rafael Knuth wrote: > Hej there, > >> I use any() and all() frequently. For example, suppose you have a >> function that takes a list of numbers, and they are all supposed to be >> positive. >> >> def calculate_values(numbers): >> if all(number > 0 for number in numbers): >> # do the

Re: [Tutor] Built In Functions

2013-12-17 Thread Rafael Knuth
Hej there, > I use any() and all() frequently. For example, suppose you have a > function that takes a list of numbers, and they are all supposed to be > positive. > > def calculate_values(numbers): > if all(number > 0 for number in numbers): > # do the calculation > else: >