Re: [Tutor] Another assert() question

2008-07-14 Thread Dick Moores
At 12:51 AM 7/14/2008, Alan Gauld wrote: "Dick Moores" <[EMAIL PROTECTED]> wrote 5.10 Boolean operations "In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: |False|, |None|, numeric zero of a

Re: [Tutor] Another assert() question

2008-07-14 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote 5.10 Boolean operations "In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: |False|, |None|, numeric zero of all types, and empty strings and container

Re: [Tutor] Another assert() question

2008-07-13 Thread Dick Moores
At 03:57 PM 7/13/2008, bob gailer wrote: When all else fails RTFM: 5.10 Boolean operations "In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: |False|, |None|, numeric zero of all types, and

Re: [Tutor] Another assert() question

2008-07-13 Thread bob gailer
When all else fails RTFM: 5.10 Boolean operations "In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: |False|, |None|, numeric zero of all types, and empty strings and containers (including st

Re: [Tutor] Another assert() question

2008-07-13 Thread Marc Tompkins
On Sun, Jul 13, 2008 at 1:06 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > In other words, "(3,2)" isn't exactly the same as "True" - but it doesn't > evaluate to False, either, so it's true. > > > So what does (3,2) evaluate to? Or is that a meaningless question? However > in the following exampl

Re: [Tutor] Another assert() question

2008-07-13 Thread Dick Moores
At 08:46 PM 7/12/2008, Marc Tompkins wrote: On Sat, Jul 12, 2008 at 8:10 PM, Dick Moores <[EMAIL PROTECTED]> wrote: But why will a tuple with two elements will always evaluate to True? In [2]: (3,5) == True Out[2]: False In [3]: ("qwerty", "asdfg") == True Out[3]: False In [4]: The valu

Re: [Tutor] Another assert() question

2008-07-13 Thread Dick Moores
At 12:40 PM 7/13/2008, Martin Walsh wrote: Dick Moores wrote: > At 11:44 AM 7/13/2008, Steve Willoughby wrote: >> Dick Moores wrote: >>> Yes! A rule, not logic. I'm not contradicting Kent, just helping >>> myself understand. First the rule, then logic in the application of >>> the rule. And I ass

Re: [Tutor] Another assert() question

2008-07-13 Thread Marcel Wunderlich
Hi Dick, because set(list) creates an unsorted collection without duplicate entrys of the items in the list. If you pass an empty list, the resulting set will also be an empty collection. A list containing an empty list evaluates non false, since it's not empty. Maybe it helps you to compar

Re: [Tutor] Another assert() question

2008-07-13 Thread Martin Walsh
Dick Moores wrote: > At 11:44 AM 7/13/2008, Steve Willoughby wrote: >> Dick Moores wrote: >>> Yes! A rule, not logic. I'm not contradicting Kent, just helping >>> myself understand. First the rule, then logic in the application of >>> the rule. And I assume the rule is there in Python because it ma

Re: [Tutor] Another assert() question

2008-07-13 Thread Dick Moores
At 11:44 AM 7/13/2008, Steve Willoughby wrote: Dick Moores wrote: Yes! A rule, not logic. I'm not contradicting Kent, just helping myself understand. First the rule, then logic in the application of the rule. And I assume the rule is there in Python because it makes things work better. Yes, so a

Re: [Tutor] Another assert() question

2008-07-13 Thread Steve Willoughby
Dick Moores wrote: Yes! A rule, not logic. I'm not contradicting Kent, just helping myself understand. First the rule, then logic in the application of the rule. And I assume the rule is there in Python because it makes things work better. Yes, so a statement like "if foo:" becomes an idiom f

Re: [Tutor] Another assert() question

2008-07-13 Thread Dick Moores
At 12:50 AM 7/13/2008, Alan Gauld wrote: "Dick Moores" <[EMAIL PROTECTED]> wrote But why will a tuple with two elements will always evaluate to True? Thats the rule for evaluationg collections in Python. An empty collection is False. Anything else is therefore true Yes! A rule, not logic. I'm no

Re: [Tutor] Another assert() question

2008-07-13 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote But why will a tuple with two elements will always evaluate to True? Thats the rule for evaluationg collections in Python. An empty collection is False. Anything else is therefore true if []: -> false if [1,2]: -> true if (): -> false if (1,2) - True

Re: [Tutor] Another assert() question

2008-07-12 Thread Martin Walsh
Dick Moores wrote: > At 07:39 PM 7/12/2008, Kent Johnson wrote: >> On Sat, Jul 12, 2008 at 6:03 PM, Dick Moores <[EMAIL PROTECTED]> wrote: >> > At 01:34 PM 7/12/2008, Kent Johnson wrote: >> >> >> In [2]: assert(False, "Asserted false") >> >> >> >> This is "assert condition" where the condition is a

Re: [Tutor] Another assert() question

2008-07-12 Thread Marc Tompkins
On Sat, Jul 12, 2008 at 8:10 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > But why will a tuple with two elements will always evaluate to > True? > > In [2]: (3,5) == True > Out[2]: False > In [3]: ("qwerty", "asdfg") == True > Out[3]: False > In [4]: > > The value formally known as True is only on

Re: [Tutor] Another assert() question

2008-07-12 Thread Dick Moores
At 07:39 PM 7/12/2008, Kent Johnson wrote: On Sat, Jul 12, 2008 at 6:03 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > At 01:34 PM 7/12/2008, Kent Johnson wrote: >> In [2]: assert(False, "Asserted false") >> >> This is "assert condition" where the condition is a tuple with two >> elements, hence t

Re: [Tutor] Another assert() question

2008-07-12 Thread Kent Johnson
On Sat, Jul 12, 2008 at 6:03 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > At 01:34 PM 7/12/2008, Kent Johnson wrote: >> In [2]: assert(False, "Asserted false") >> >> This is "assert condition" where the condition is a tuple with two >> elements, hence true so there is no output. > > In [13]: asser

Re: [Tutor] Another assert() question

2008-07-12 Thread Dick Moores
At 01:34 PM 7/12/2008, Kent Johnson wrote: On Sat, Jul 12, 2008 at 4:01 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > _Python in a NutShell_, p. 138 has a bit on the assert statement which I > don't completely understand. > > It says the syntax is > > assert condition[, expression] > > I was hopin

Re: [Tutor] Another assert() question

2008-07-12 Thread Dick Moores
At 01:24 PM 7/12/2008, Danny Yoo wrote: Content-Transfer-Encoding: 7bit Content-Disposition: inline > In my code I have > > assert(len(list(set(colors_used_this_cycle))) == > len(colors_used_this_cycle), "A color has been used twice!") > > But it doesn't work. Cases where a color has been used m

Re: [Tutor] Another assert() question

2008-07-12 Thread Dick Moores
At 01:28 PM 7/12/2008, Michiel Overtoom wrote: Dick wrote: > I was hoping to put some sort of explanation of failure in an > assert statement. But how to do it? > So I'd like to know what that 'expression' in the syntax can be, > and how to use it. I think it would help if you separate the dete

Re: [Tutor] Another assert() question

2008-07-12 Thread Kent Johnson
On Sat, Jul 12, 2008 at 4:01 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > _Python in a NutShell_, p. 138 has a bit on the assert statement which I > don't completely understand. > > It says the syntax is > > assert condition[, expression] > > I was hoping to put some sort of explanation of failure

Re: [Tutor] Another assert() question

2008-07-12 Thread Michiel Overtoom
Dick wrote: > I was hoping to put some sort of explanation of failure in an > assert statement. But how to do it? > So I'd like to know what that 'expression' in the syntax can be, > and how to use it. I think it would help if you separate the detection of duplicate colors from the assert state

Re: [Tutor] Another assert() question

2008-07-12 Thread Danny Yoo
> In my code I have > > assert(len(list(set(colors_used_this_cycle))) == > len(colors_used_this_cycle), "A color has been used twice!") > > But it doesn't work. Cases where a color has been used more than once go > right through it Let's try a simple example. Go back to the structure of an asse

[Tutor] Another assert() question

2008-07-12 Thread Dick Moores
_Python in a NutShell_, p. 138 has a bit on the assert statement which I don't completely understand. It says the syntax is assert condition[, _expression_] I was hoping to put some sort of explanation of failure in an assert statement. But how to do it? In my code I have assert(len(list(set(colo