Re: Relying on the behaviour of empty container in conditional statements

2006-07-12 Thread Roel Schroeven
Steven D'Aprano schreef: > If seq can be None as well as a sequence, doing a test "if len(seq) > 0" > won't save you because len(None) will fail. You need an explicit test > for seq being None: > > if seq is not None and len(seq) > 0 > > Or even better: > > if seq > > which Just Works regardles

Re: Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread Steven D'Aprano
On Tue, 11 Jul 2006 19:43:57 +, Roel Schroeven wrote: > I know that that is the consensus, and I mostly the form without len(), > but somehow I still feel it is not as explicit. In > > if seq: > > there is no distinction between seq is None on the one hand and seq > being a valid empty seq

Re: Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread horizon5
Interesting replies, thank you all. Since the language defines the bahviour, I'm all for using it (when appropriate). > there is no distinction between seq is None on the one hand and seq > being a valid empty sequence on the other hand. > > I feel that that is an import distinction, and it's the

Re: Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread Roel Schroeven
Simon Forman schreef: > I've been programming in python for years and I've always used this > form > > if not seq: > if seq: > > rather than the other and never had any problems. > > Anyone presenting arguments in favor of the len() form is IMHO, not > "getting it". AFAIK, python is not "smart"

Re: Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread Simon Forman
horizon5 wrote: > Hi, > > my collegues and I recently held a coding style review. > All of the code we produced is used in house on a commerical project. > One of the minor issues I raised was the common idiom of specifing: > > > if len(x) > 0: > do_something() > > Instead of using the langua

Re: Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread Maric Michaud
Le mardi 11 juillet 2006 13:52, horizon5 a écrit : > Arguments that have been presented for using len(x) > 0 to > test emptiness of a container include: >   - It's safer >   - Not relying on weird behaviour of the language >   - Explicit is better than implicit (as stated by 'this' module, Zen > of

Re: Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread Daniel Dittmar
horizon5 wrote: > Hi, > > my collegues and I recently held a coding style review. > All of the code we produced is used in house on a commerical project. > One of the minor issues I raised was the common idiom of specifing: > > > if len(x) > 0: > do_something() > > Instead of using the lang

Re: Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread Steven D'Aprano
On Tue, 11 Jul 2006 04:52:42 -0700, horizon5 wrote: > Hi, > > my collegues and I recently held a coding style review. > All of the code we produced is used in house on a commerical project. > One of the minor issues I raised was the common idiom of specifing: > > > if len(x) > 0: > do_somet

Re: Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread Bruno Desthuilliers
horizon5 wrote: > Hi, > > my collegues and I recently held a coding style review. > All of the code we produced is used in house on a commerical project. > One of the minor issues I raised was the common idiom of specifing: > > > if len(x) > 0: > do_something() > > Instead of using the lang

Relying on the behaviour of empty container in conditional statements

2006-07-11 Thread horizon5
Hi, my collegues and I recently held a coding style review. All of the code we produced is used in house on a commerical project. One of the minor issues I raised was the common idiom of specifing: if len(x) > 0: do_something() Instead of using the language-defined bahviour, as stated by PE