Re: Einstein summation notation

2009-07-22 Thread Ethan Furman
Paul Rubin wrote: Ethan Furman writes: Or if any(p for p in [header, body, footer, whatever, ...]) No need for the genexp: if any([header, body, footer, whatever, ...]) But, you are using the built-in bool cast either way. Right you are -- and if any([header, body, footer, whateve

Re: Einstein summation notation

2009-07-17 Thread Paul Rubin
Ethan Furman writes: > Or if any(p for p in [header, body, footer, whatever, ...]) No need for the genexp: if any([header, body, footer, whatever, ...]) But, you are using the built-in bool cast either way. -- http://mail.python.org/mailman/listinfo/python-list

Re: Einstein summation notation

2009-07-17 Thread Matthew Barnett
Steven D'Aprano wrote: On Fri, 17 Jul 2009 16:09:03 +0100, MRAB wrote: Python did always have True and False. Oops! I meant "didn't", of course. $ python1.5 Python 1.5.2 (#1, Apr 1 2009, 22:55:54) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Copyright 1991-1995 Stichting Mathematis

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Paul Rubin
Steven D'Aprano writes: > Since I haven't specified an implementation for assemble_page, it could > be doing *anything*. Perhaps it has to talk to a remote database over a > slow link, perhaps it generates 300 lines of really inefficient HTML code > with no content, perhaps it sends a print job

Re: Einstein summation notation

2009-07-17 Thread Ethan Furman
Paul Rubin wrote: Steven D'Aprano writes: def assemble_page(header, body, footer): if header or body or footer: do_lots_of_expensive_processing() else: do_nothing_gracefully() Why should the processing be expensive if all three fields are empty? if header or body o

Re: Einstein summation notation

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 16:09:03 +0100, MRAB wrote: > Python did always have True and False. $ python1.5 Python 1.5.2 (#1, Apr 1 2009, 22:55:54) [GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> True, False Traceback (innermost last

Re: Einstein summation notation

2009-07-17 Thread Jerry Hill
On Fri, Jul 17, 2009 at 11:09 AM, MRAB wrote: > Python did always have True and False. Only if "always" means "since python 2.2.1". See: http://www.python.org/doc/2.3/whatsnew/section-bool.html and http://www.python.org/dev/peps/pep-0285/ for details. -- Jerry -- http://mail.python.org/mailma

Re: Einstein summation notation

2009-07-17 Thread MRAB
koranthala wrote: That test was designed to treat None as a boolean False, without noticing that numeric 0 is also treated as False and could make the test do the wrong thing. This is an extremely common type of error. Actually, I felt that 0 not being considered False would be a better option

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 07:12:51 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> def assemble_page(header, body, footer): >> if header or body or footer: >> do_lots_of_expensive_processing() >> else: >> do_nothing_gracefully() > > Why should the processing be expensive

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Paul Rubin
Steven D'Aprano writes: > def assemble_page(header, body, footer): > if header or body or footer: > do_lots_of_expensive_processing() > else: > do_nothing_gracefully() Why should the processing be expensive if all three fields are empty? > if header or body or footer:

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Steven D'Aprano
On Fri, 17 Jul 2009 00:34:00 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> It is very useful to be able to write e.g.: >> >> if header or body or footer: >> print assemble_page(header, body, footer) >> >> and have empty strings to be equivalent to False. > > Why doesn't assemble_pag

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Paul Rubin
Steven D'Aprano writes: > It is very useful to be able to write e.g.: > if header or body or footer: > print assemble_page(header, body, footer) > and have empty strings to be equivalent to False. Why doesn't assemble_page properly handle the case where header, body, and footer are all empty?

Re: Einstein summation notation (was: question of style)

2009-07-17 Thread Steven D'Aprano
On Thu, 16 Jul 2009 23:13:51 -0700, koranthala wrote: >> That test was designed to treat None as a boolean False, without >> noticing that numeric 0 is also treated as False and could make the >> test do the wrong thing. This is an extremely common type of error. > > Actually, I felt that 0 not

Re: Einstein summation notation (was: question of style)

2009-07-16 Thread Chris Rebert
On Thu, Jul 16, 2009 at 11:13 PM, koranthala wrote: >> That test was designed to treat None as a boolean False, without >> noticing that numeric 0 is also treated as False and could make the >> test do the wrong thing.  This is an extremely common type of error. > > Actually, I felt that 0 not bein

Re: Einstein summation notation (was: question of style)

2009-07-16 Thread koranthala
> That test was designed to treat None as a boolean False, without > noticing that numeric 0 is also treated as False and could make the > test do the wrong thing. This is an extremely common type of error. Actually, I felt that 0 not being considered False would be a better option. I had lot of

Einstein summation notation (was: question of style)

2009-07-16 Thread Erik Max Francis
Albert van der Horst wrote: Einstein introduced the summation convention for indices that are used twice. Leaving out summation signs is absolutely hideous, but it has saved generations of physicists of loosing track (and their minds.) There is a joke among mathematicians that if Einstein hadn'